cjr1221 @ 2024-01-10 20:34:58
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
#include<iostream>
#include<math.h>
#include<algorithm>
int n, m;
char board[1001][1001];
bool come[1001][1001];
long long maax = 0;
void dfs(int y, int x, long long sum)
{
if (y > n || x > n || y < 1 || x < 1 || come[y][x])
{
return;
}
come[y][x] = 1;
char mid = board[y][x];
int turn = 0;
if (board[y][x + 1] != mid)
dfs(y, x + 1, sum + 1);
else
turn++;
if (board[y][x - 1] != mid)
dfs(y, x - 1, sum + 1);
else
turn++;
if (board[y + 1][x] != mid)
dfs(y + 1, x, sum + 1);
else
turn++;
if (board[y - 1][x] != mid)
dfs(y - 1, x, sum + 1);
else
turn++;
maax = max(maax, sum);
return;
}
int main()
{
scanf("%d %d", &n, &m);
getchar();
for (int i = 1; i <= n; i++)
{
for (int t = 1; t <= n; t++)
scanf("%c", &board[i][t]);
getchar();
}
while (m-- > 0)
{
int y, x;
scanf("%d%d", &y, &x);
memset(come, 0, sizeof(come));
dfs(y, x, 1);
printf("%lld\n", maax);
maax = 0;
}
return 0;
}
明明自己的数据和样例都过了,是我理解错题意了吗