20250712
//캔디팡_BFS (해결)
/*
#include <stdio.h>
#include <string.h>
int s, r=0, cnt=0, i, j;
int a[9][9]={};
int queue[50][2]={};
int front=-1, back=-1;
int px, py;
int color;
void push(int x, int y)
{
if(x<1 || x>7 || y<1|| y>7 || a[x][y]!=color)
return ;
r++;
back++;
queue[back][0]=x;
queue[back][1]=y;
a[x][y]=0;
}
void pop()
{
if(back==front){
return ;
}
front++;
px = queue[front][0];
py = queue[front][1];
}
void bfs(int x, int y)
{
push(x, y);
while(front!=back){
pop();
push(px-1, py);
push(px, py-1);
push(px+1, py);
push(px, py+1);
}
}
int main()
{
for(i=1; i<=7; i++){
for(j=1; j<=7; j++){
scanf("%d", &a[i][j]);
}
}
for(i=1; i<=7; i++){
for(j=1; j<=7; j++){
if(a[i][j]!=0){
color = a[i][j];
bfs(i, j);
if(r>=3){
cnt++;
}
r=0;
}
}
}
printf("%d", cnt);
return 0;
}
*/
//숫자 등고선_BFS (진행중)
#include <stdio.h>
#include <string.h>
int s;
int a[101][101]={};
int queue[10001][2]={};
int front=-1, back=-1;
int px, py;
int c=1;
void push(int h, int r)
{
if(h<1 || h>s || r<1 || r>s || a[h][r]!=0)
return;
back++;
queue[back][0]=h;
queue[back][1]=r;
a[h][r] = c;
}
void pop()
{
if(back==front){
return ;
}
front++;
px = queue[front][0];
py = queue[front][1];
}
void bfs(int x, int y)
{
push(x, y);
while(front!=back){
pop();
push(px-1, py);
push(px, py-1);
push(px+1, py);
push(px, py+1);
}
}
int main()
{
int x, y, i, j;
scanf("%d", &s);
scanf("%d %d", &x, &y);
bfs(x, y);
for(i=1; i<=s; i++){
for(j=1; j<=s; j++){
printf("%2d ", a[i][j]);
}
printf("\n");
}
return 0;
}
//체스 말 이동
/*
#include <stdio.h>
int main()
{
return 0;
}
*/
//토마토_BFS
/*
#include <stdio.h>
int main()
{
return 0;
}
*/




