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 |
Re:用队列和BFS,第一次TL了,第二次ACIn Reply To:用队列和BFS,第一次TL了,第二次AC Posted by:zpdlut at 2010-08-09 13:46:29 > #include<iostream> > #include<queue> > using namespace std; > #define MAX 101 > int set[MAX][MAX]; > int visited[MAX][MAX]; > int step[MAX][MAX]; > int move[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; > int r,c,k; > int result; > struct farm > { > int r,c; > }; > queue<farm> q; > void BFS(int x,int y) > { > > visited[x][y]=1; > farm m; > m.r =x; > m.c =y; > q.push(m); > step[x][y] = 1; > result = 1 ; > while(!q.empty()){ > farm temp = q.front(); > q.pop(); > for(int i=0;i<4;i++) > { > x = temp.r; > y = temp.c; > x+=move[i][0]; > y+=move[i][1]; > if(x>=1&&x<=r&&y>=1&&y<=c) > { > if(set[x][y]&&!visited[x][y]){ > visited[x][y]=1; > result++; > m.r = x; > m.c = y; > q.push(m); > > } > } > > } > } > > } > int main() > { > > cin>>r>>c>>k; > int a,b; > int final = 0; > for(int i=0;i<k;i++){ > cin>>a>>b; > set[a][b] = 1; > } > for(int i=1;i<=r;i++){ > for(int j=1;j<=c;j++){ > if(set[i][j]==0||visited[i][j]==1) > continue; > > BFS(i,j); > if(result > final) > final = result; > > } > } > cout<<final<<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