标签:stream 一个 org 最大值 apt www. tps south http
原题 :The Castle
以下为题解部分:明明辣么简单的一道题,硬是搞了1.5h,WTF?以下列出本题的一些要点。
详细见丑*代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
main() {}
const int fx[]= {0,-1,0,1};//W,N,E,S
const int fy[]= {-1,0,1,0};
int n,m,id[51][51],a[51][51],tot,room[50*50+1];
void clor(int x,int y,int c) {
id[x][y]=c;
room[c]++;//面积
for(int i=0,nx,ny; i<4; i++)
if(!(a[x][y]&(1<<i))) {//美丽的二进制解析
nx=x+fx[i],ny=y+fy[i];
if(nx>0&&ny>0&&nx<=n&&ny<=m&&!id[nx][ny])
clor(nx,ny,c);
}
}
int entry() {
scanf("%d%d",&m,&n);
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++)
scanf("%d",&a[i][j]);
}
for(int i=1; i<=n; i++) {//染色
for(int j=1; j<=m; j++)
if(!id[i][j])
clor(i,j,++tot);
}
int maxn=*std::max_element(room+1,room+tot+1);
printf("%d\n""%d\n",tot,maxn);
int ans1=maxn,ans2=maxn;
int x1=n,y1=0,x2=n,y2=0;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++) {
if((a[i][j]&2)&&id[i][j]!=id[i-1][j]&&ans1<=room[id[i][j]]+room[id[i-1][j]]) {
if(ans1!=room[id[i][j]]+room[id[i-1][j]]) x1=i,y1=j;
else if(j<y1) y1=j,x1=i;//West
else if(j==y1 && i>x1) x1=i;//South
ans1=room[id[i][j]]+room[id[i-1][j]];
}//北墙
if((a[i][j]&4)&&id[i][j]!=id[i][j+1]&&ans2<=room[id[i][j]]+room[id[i][j+1]]) {
if(ans2!=room[id[i][j]]+room[id[i][j+1]]) x2=i,y2=j;
else if(j<y2) y2=j,x2=i;//West
else if(j==y2 && i>x2) x2=i;//South
ans2=room[id[i][j]]+room[id[i][j+1]];
}//东墙
}
if(ans1>ans2) printf("%d\n%d %d N\n",ans1,x1,y1);
else if(ans1<ans2) printf("%d\n%d %d E\n",ans2,x2,y2);//maxmize result
else if(y1<y2) printf("%d\n%d %d N\n",ans1,x1,y1);
else if(y1>y2) printf("%d\n%d %d E\n",ans2,x2,y2);//west
else if(x1>x2) printf("%d\n%d %d N\n",ans1,x1,y1);
else if(x1<x2) printf("%d\n%d %d E\n",ans2,x2,y2);//south
else printf("%d\n%d %d N\n",ans1,x1,y1);
}
int aptal=entry();
标签:stream 一个 org 最大值 apt www. tps south http
原文地址:http://www.cnblogs.com/FreeRing/p/7904348.html