/**//*
ID: lorelei3
TASK: castle
LANG: C++
*/
#include <fstream>
using namespace std;
const int MAX = 55;
int t;
int g[MAX][MAX];
int area[3000];
bool f[MAX][MAX][5];
bool floodfill(int x, int y){
if(g[x][y]!=-1) return false;
g[x][y]=t;
area[t]++;
if(!f[x][y][1]) floodfill(x, y-1);
if(!f[x][y][2]) floodfill(x-1, y);
if(!f[x][y][3]) floodfill(x, y+1);
if(!f[x][y][4]) floodfill(x+1, y);
return true;
}
int main(){
int i,j,k,n,m;
ifstream in("castle.in");
ofstream out("castle.out");
in>>m>>n;
for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j){
in>>k;
if(k>=8) { k-=8; f[i][j][4]=true; }
if(k>=4) { k-=4; f[i][j][3]=true; }
if(k>=2) { k-=2; f[i][j][2]=true; }
if(k>=1) { k-=1; f[i][j][1]=true; }
g[i][j] = -1;
}
t=0;
for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j)
if(floodfill(i,j))
t++;
int max_room=0;
for(i=0;i<=t;++i)
max_room= max_room>area[i]? max_room:area[i];
out<<t<<endl;
out<<max_room<<endl;
int max_area=0, mx=0, my=0, x=0;
char ch=0;
for(j=1; j<=m; ++j)
for(i=n; i>=1; i--){
if(g[i][j]!=g[i-1][j] && i-1!=0)
x = area[g[i][j]]+area[g[i-1][j]];
if(x>max_area){
max_area = x; mx = i; my = j; ch='N';
}
if(g[i][j]!=g[i][j+1] && j+1<=m)
x = area[g[i][j]]+area[g[i][j+1]];
if(x>max_area){
max_area = x; mx = i; my = j; ch='E';
}
}
out<<max_area<<endl;
out<<mx<<" "<<my<<" "<<ch<<endl;
return 0;
}
posted on 2010-11-21 00:43
小阮 阅读(131)
评论(0) 编辑 收藏 引用 所属分类:
USACO