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:这哪里错了?? 样例都对啊~~!In Reply To:这哪里错了?? 样例都对啊~~! Posted by:lyz963254 at 2015-01-04 22:39:52 > #include <iostream> > #include <cstdio> > #include <cstring> > #include <queue> > > using namespace std; > > const int M = 1015; > > int i,j,k; > > int Max (int x ,int y) > { > return x>y?x:y ; > } > > struct p > { > int x; > int y; > int step; > }; > > int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; > > char a[M][M]; > int visit[M][M]; > int n,m; > int tmpx,tmpy; > int tmp; > > void bfs(int x,int y) > { > memset(visit,0,sizeof(visit)); > int i; > p t; > p s; > t.x = x; > t.y = y; > t.step = 0; > queue<p>q; > > q.push(t); > visit[t.x][t.y] = 1; > while(!q.empty()){ > p w; > w = q.front(); > q.pop(); > for(i=0;i<4;i++){ > s.x = w.x + dir[i][0]; > s.y = w.y + dir[i][1]; > > if(s.x>=0&&s.x<n&&s.y>=0&&s.y<m&&visit[s.x][s.y]==0&&a[s.x][s.y]!='#'){ > s.step = w.step + 1; > visit[s.x][s.y] = 1; > if(s.step > tmp){ > tmpx = s.x; > tmpy = s.y; > tmp = s.step; > } > q.push(s); > } > } > } > > } > > int main () > { > int t; > scanf("%d",&t); > while(t--){ > scanf("%d%d",&n,&m); > memset(a,0,sizeof(a)); > int i; > for(i=0;i<m;i++){ > scanf("%s",a[i]); > } > int x,y; > for(i=0;i<m;i++){ > int f = 0; > for(j=0;j<n;j++){ > if(a[i][j] == '.') { > x = i; > y = j; > f = 1; > break ; > } > } > if(f) break; > } > bfs(x,y); > x = tmpx; > y = tmpy; > bfs(x,y); > int ans = tmp; > printf("Maximum rope length is %d.\n",ans); > > } > > > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator