/*
ID: cm750621
PROG: castle
LANG: C++
*/
#include<cstdio>
#include<cstring>
int castle[54][54][4],vis[54][54],wall[3];
int s,size[2501];
int big=1,max,k=1,large;
void DFS(int x,int y){
if(!castle[x][y][1])
return ;
castle[x][y][1]=0;
castle[x][y][2]=size[big];
if(castle[x][y][0]==1){
DFS(x+1,y);DFS(x-1,y);DFS(x,y+1);
}
if(castle[x][y][0]==2){
DFS(x,y-1);DFS(x,y+1);DFS(x+1,y);
}
if(castle[x][y][0]==3){
DFS(x,y+1);DFS(x+1,y);
}
if(castle[x][y][0]==4){
DFS(x-1,y);DFS(x,y-1);DFS(x+1,y);
}
if(castle[x][y][0]==5){
DFS(x-1,y);DFS(x+1,y);
}
if(castle[x][y][0]==6){
DFS(x,y-1);DFS(x+1,y);
}
if(castle[x][y][0]==7){
DFS(x+1,y);
}
if(castle[x][y][0]==8){
DFS(x,y-1);DFS(x,y+1);DFS(x-1,y);
}
if(castle[x][y][0]==9){
DFS(x-1,y);DFS(x,y+1);
}
if(castle[x][y][0]==10){
DFS(x,y-1);DFS(x,y+1);
}
if(castle[x][y][0]==11){
DFS(x,y+1);
}
if(castle[x][y][0]==12){
DFS(x,y-1);DFS(x-1,y);
}
if(castle[x][y][0]==13){
DFS(x-1,y);
}
if(castle[x][y][0]==14){
DFS(x,y-1);
}
if(castle[x][y][0]==15)
return ;
if(castle[x][y][0]==0){
DFS(x,y-1);DFS(x,y+1);DFS(x-1,y);DFS(x+1,y);
}
return ;
}
void dfs(int x,int y){
if(vis[x][y]==1)
return ;
castle[x][y][1]=1;
large++;
vis[x][y]=1;
castle[x][y][3]=k;
if(castle[x][y][0]==1){
dfs(x+1,y);dfs(x-1,y);dfs(x,y+1);
}
if(castle[x][y][0]==2){
dfs(x,y-1);dfs(x,y+1);dfs(x+1,y);
}
if(castle[x][y][0]==3){
dfs(x,y+1);dfs(x+1,y);
}
if(castle[x][y][0]==4){
dfs(x-1,y);dfs(x,y-1);dfs(x+1,y);
}
if(castle[x][y][0]==5){
dfs(x-1,y);dfs(x+1,y);
}
if(castle[x][y][0]==6){
dfs(x,y-1);dfs(x+1,y);
}
if(castle[x][y][0]==7){
dfs(x+1,y);
}
if(castle[x][y][0]==8){
dfs(x,y-1);dfs(x,y+1);dfs(x-1,y);
}
if(castle[x][y][0]==9){
dfs(x-1,y);dfs(x,y+1);
}
if(castle[x][y][0]==10){
dfs(x,y-1);dfs(x,y+1);
}
if(castle[x][y][0]==11){
dfs(x,y+1);
}
if(castle[x][y][0]==12){
dfs(x,y-1);dfs(x-1,y);
}
if(castle[x][y][0]==13){
dfs(x-1,y);
}
if(castle[x][y][0]==14){
dfs(x,y-1);
}
if(castle[x][y][0]==15)
return ;
if(castle[x][y][0]==0){
dfs(x,y-1);dfs(x,y+1);dfs(x-1,y);dfs(x+1,y);
}
return ;
}
int i,j,m,n,a,b,c;
int main(){
freopen("castle.in", "r", stdin);
freopen("castle.out", "w", stdout);
scanf("%d%d",&m,&n);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&castle[i][j][0]);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++){
if(!vis[i][j]){
s++;
dfs(i,j);
k++;
size[big]=large;
large=0;
DFS(i,j);
if(size[big]>max)
max=size[big];
big++;
}
}
for(j=1;j<=m;j++)
for(i=n;i>=1;i--){
if(i>1&&castle[i][j][3]!=castle[i-1][j][3]&&a<castle[i][j][2]+castle[i-1][j][2]){
a=castle[i][j][2]+castle[i-1][j][2];
wall[0]=i;
wall[1]=j;
wall[2]='N';
}
if(j<m&&castle[i][j][3]!=castle[i][j+1][3]&&a<castle[i][j][2]+castle[i][j+1][2]){
a=castle[i][j][2]+castle[i][j+1][2];
wall[0]=i;
wall[1]=j;
wall[2]='E';
}
}
printf("%d\n%d\n",s,max);
printf("%d\n%d %d %c\n",a,wall[0],wall[1],wall[2]);
return 0;
}
usaco 2.1.1 castle
最新推荐文章于 2017-02-18 12:26:40 发布