| ||||||||||
| 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 | |||||||||
这题数据有超出题目要求,我开50*50的数组WA,开51*51AC,下面是我的代码,我想没有越界之处#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define clr(x) memset(x,0,sizeof(x))
// 1 (= wall to the west), 2 (= wall to the north),
// 4 (= wall to the east), 8 (= wall to the south).
const int D[][2]={{0,-1},{-1,0},{0,1},{1,0} };
const char wall[]={ 1,2,4,8 };
int dfn;
const int maxN=50;
char mark[maxN][maxN],M[maxN][maxN];
int h,w;
void dfs(int i,int j)
{
mark[i][j]=1; dfn++;
for(int d=0;d<4;d++) {
int ii=i+D[d][0],jj=j+D[d][1];
if(ii<h && ii>=0 && jj<w && jj>=0
&& !mark[ii][jj] && (M[i][j] & wall[d])==0)
dfs(ii,jj);
}
}
int main()
{
//freopen("test.in","r",stdin);
int i,j,k,ca;
while(scanf("%d %d",&h,&w)!=EOF) {
for(i=0;i<h;i++)
for(j=0;j<w;j++)
scanf("%d",&M[i][j]);
int m=0,n=0;
clr(mark);
for(i=0;i<h;i++)
for(j=0;j<w;j++)
if(!mark[i][j]) {
n++; dfn=0;
dfs(i,j);
if(dfn>m) m=dfn;
}
printf("%d\n%d\n",n,m);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator