记录编号 |
111987 |
评测结果 |
AAAAAAAA |
题目名称 |
城堡 |
最终得分 |
100 |
用户昵称 |
slyrabbit |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2014-07-14 16:29:45 |
内存使用 |
0.35 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
class castle
{
public:
int x;
bool d[5];
void f()
{
x=0;
memset(d,0,sizeof(d));
}
};
castle sly[52][52];
int m,n,s_room,s_first_max=0,s_last_max=0,temp,s[2501]={0},i_ans=0,j_ans=60;
bool t;
char d_ans;
void build(int i,int j,int x)
{
for(int k=1;k<=4;k++)
{
if(x&1)
sly[i][j].d[k]=1;
x>>=1;
}
}
void search(int i,int j,int x)
{
if(sly[i][j].x!=1)
return;
t=1;
temp++;
sly[i][j].x=x;
if(sly[i][j].d[1]==0)
{
search(i,j-1,x);
}
if(sly[i][j].d[2]==0)
{
search(i-1,j,x);
}
if(sly[i][j].d[3]==0)
{
search(i,j+1,x);
}
if(sly[i][j].d[4]==0)
{
search(i+1,j,x);
}
}
void rebuild(int i,int j)
{
if(sly[i-1][j].x!=sly[i][j].x)
{
if(s[sly[i][j].x-2]+s[sly[i-1][j].x-2]>s_last_max&&sly[i-1][j].x!=0)
{
s_last_max=s[sly[i][j].x-2]+s[sly[i-1][j].x-2];
i_ans=i;
j_ans=j;
d_ans='N';
}
}
if(sly[i][j+1].x!=sly[i][j].x)
{
if((s[sly[i][j].x-2]+s[sly[i][j+1].x-2]>s_last_max)&&sly[i][j+1].x!=0)
{
s_last_max=s[sly[i][j].x-2]+s[sly[i][j+1].x-2];
i_ans=i;
j_ans=j;
d_ans='E';
}
}
}
int main()
{
freopen("castle.in","r",stdin);
freopen("castle.out","w",stdout);
cin>>m>>n;
int x;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
sly[i][j].x=1;
cin>>x;
build(i,j,x);
}
}
int newcolor=2;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
temp=0;
t=0;
search(i,j,newcolor);
if(temp>s_first_max)
s_first_max=temp;
if(t)
{
s[newcolor-2]=temp;
newcolor++;
s_room++;
}
}
}
for(int j=1;j<=m;j++)
{
for(int i=n;i>=1;i--)
{
rebuild(i,j);
}
}
cout<<s_room<<endl<<s_first_max<<endl<<s_last_max<<endl<<i_ans<<" "<<j_ans<<" "<<d_ans;
return 0;
}