代码
#include <bits/stdc++.h>
using namespace std;
int n, m, maxs = -1, maxcur;
int dex, dey, dew, demax=-1;
int mp[55][55];
int color[55][55], c;
int sq[2510];
char dir[5] = "ANE";
void north(int x, int y){
if(!(mp[x][y] & 2)) return;
if(x-1 <= 0) return;
if(color[x][y] == color[x-1][y]) return;
// printf("north: x=%d y=%d mp[%d][%d]=%d\n", x, y, x, y, mp[x][y]);
if(sq[color[x][y]] + sq[color[x-1][y]] >= demax){
demax = sq[color[x][y]] + sq[color[x-1][y]];
dex = x;
dey = y;
dew = 1;
}
}
void east(int x, int y){
if(!(mp[x][y] & 4)) return;
if(y+1 > m) return;
if(color[x][y] == color[x][y+1]) return;
// printf("east: x=%d y=%d mp[%d][%d]=%d\n", x, y, x, y, mp[x][y]);
if(sq[color[x][y]] + sq[color[x][y+1]] >= demax){
demax = sq[color[x][y]] + sq[color[x][y+1]];
dex = x;
dey = y;
dew = 2;
}
}
void dfs(int x, int y, int cl, int s){
if(color[x][y]) return;
if(x<=0 || x>n || y<=0 || y>m) return;
maxs = max(s, maxs);
maxcur = max(maxcur, s);
color[x][y] = cl;
if(!(mp[x][y] & 1)) dfs(x, y-1, cl, maxcur+1);
if(!(mp[x][y] & 2)) dfs(x-1, y, cl, maxcur+1);
if(!(mp[x][y] & 4)) dfs(x, y+1, cl, maxcur+1);
if(!(mp[x][y] & 8)) dfs(x+1, y, cl, maxcur+1);
}
int main(){
scanf("%d %d", &m, &n);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
scanf("%d", &mp[i][j]);
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(!color[i][j]){
maxcur = -1;
c++;
dfs(i, j, c, 1);
sq[c] = maxcur;
}
}
}
for(int i=1; i<=n; i++){
for(int j=m; j>=1; j--){
north(i, j);
east(i, j);
}
}
printf("%d\n%d\n%d\n%d %d %c", c, maxs, demax, dex, dey, dir[dew]);
return 0;
}
实在找不到错了,请大佬帮帮忙QWQ