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 |
BFS 怎么没过????#include<iostream> #include<string.h> using namespace std; #define maxn 110 int n,m; bool flag[maxn][maxn]; int que[2001][3]; int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}}; int bfs(int x,int y) { // cout<<x<<" "<<y<<endl; int i,tail=0,head=0,tx,ty; que[0][0]=x;que[0][1]=y;flag[x][y]=true; tail++; while(head<tail) { for(i=0;i<4;i++) { tx=que[head][0]+dir[i][0]; ty=que[head][1]+dir[i][1]; if(flag[tx][ty]==false&&tx>=1&&tx<=n&&ty>=1&&ty<=m) { flag[tx][ty]=true; que[tail][0]=tx; que[tail][1]=ty; tail++; } } head++; } return tail; } int main() { int i,j,k,x,y,MAX,s; while(cin>>n>>m>>k) { memset(flag,true,sizeof(flag)); for(i=1;i<=5;i++) { cin>>x>>y; flag[x][y]=false; } MAX=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { if(flag[i][j]==false) { s=bfs(i,j); if(s>MAX) MAX=s; } } cout<<MAX<<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