标签:tput step 数据 problem eof code push 输入 node
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 27258 Accepted Submission(s): 6661
#include<bits/stdc++.h> using namespace std; const int N=100; char mp[N][N]; int visited[N][N]; int n,m,xx,yy,x2,y2,k; int _x[4]={1,0,-1,0}; int _y[4]={0,1,0,-1}; struct node{ int x,y; int step; }G; int check(int x,int y){ if(x>=1&&x<=m&&y>=1&&y<=n&&mp[x][y]!=‘*‘){ return 1; } return 0; } void BFS(){ int flag=0; queue<node>Q; Q.push(G); node first,next; while(!Q.empty()){ first=Q.front(); Q.pop(); if(first.x==y2&&first.y==x2&&first.step<=k){ flag=1; break; } next.step=first.step+1; for(int i=0;i<4;i++){ int a=first.x+_x[i]; int b=first.y+_y[i]; while(check(a,b)){ if(visited[a][b]==0){ visited[a][b]=1; next.x=a; next.y=b; Q.push(next); } a=a+_x[i]; b=b+_y[i]; } } } if(flag==1)cout<<"yes"<<endl; else cout<<"no"<<endl; } int main(){ int t; scanf("%d",&t); while(t--){ memset(visited,0,sizeof(visited)); scanf("%d%d",&m,&n); for(int i=1;i<=m;i++){ getchar(); for(int j=1;j<=n;j++){ scanf("%c",&mp[i][j]); } } scanf("%d%d%d%d%d",&k,&xx,&yy,&x2,&y2); G.x=yy; G.y=xx; G.step=-1; visited[G.x][G.y]=1; BFS(); } return 0; }
。。。
标签:tput step 数据 problem eof code push 输入 node
原文地址:http://www.cnblogs.com/ZERO-/p/7129130.html