| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用队列做的。为什么错啊,想不通。。。是不是横纵坐标搞错了还是什么啊。。。#include <iostream>
using namespace std;
int a[105][105];
int N,M,K,X,Y,k,i,j,num;
int top,end;
struct aa
{
int x;
int y;
};
aa queue[1000];
void move (int i,int j)
{
if(a[i][j+1]==0&&((j+1)<=M)){queue[top].x=j+1;queue[top++].y=i;a[i][j+1]=1;num++;}
if(a[i-1][j]==0&&((i-1)>0)){queue[top].x=j;queue[top++].y=i-1;a[i-1][j]=1;num++;}
if(a[i][j-1]==0&&((j-1)>0)){queue[top].x=j-1;queue[top++].y=i;a[i][j-1]=1;num++;}
if(a[i+1][j]==0&&((i+1)<=N)){queue[top].x=j;queue[top++].y=i+1;a[i+1][j]=1;num++;}
}
int main ()
{
while(cin>>N>>M>>K){
k=0;
top=0;
end=0;
for (i=0;i<105;i++)
{
for (j=0;j<105;j++)
{
a[i][j]=1;
}
}
for (i=1;i<=K;i++)
{
cin>>X>>Y;
a[X][Y]=0;
}
for (i=1;i<=N;i++)
{
for (j=1;j<=M;j++)
{
if(a[i][j]==0)
{
queue[top].x=j;
queue[top++].y=i;
a[i][j]=1;
num=1;
while(end!=top)
{
move(queue[end].y,queue[end].x);
end++;
}
if(num>k)k=num;
}
}
}
cout<<k<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator