标签:ret tle iostream lib while ace tput sample pop
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24452 Accepted Submission(s): 5997
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<queue> 7 #include<map> 8 #include<set> 9 #include<vector> 10 #include<cstdlib> 11 #include<string> 12 #define eps 0.000000001 13 typedef long long ll; 14 typedef unsigned long long LL; 15 using namespace std; 16 const int N=100; 17 char mp[N][N]; 18 int visited[N][N]; 19 int n,m,xx,yy,x2,y2,k; 20 int _x[4]={1,0,-1,0}; 21 int _y[4]={0,1,0,-1}; 22 struct node{ 23 int x,y; 24 int step; 25 }G; 26 int check(int x,int y){ 27 if(x>=1&&x<=m&&y>=1&&y<=n&&mp[x][y]!=‘*‘){ 28 return 1; 29 } 30 return 0; 31 } 32 void BFS(){ 33 int flag=0; 34 queue<node>Q; 35 Q.push(G); 36 node first,next; 37 while(!Q.empty()){ 38 first=Q.front(); 39 Q.pop(); 40 if(first.x==y2&&first.y==x2&&first.step<=k){ 41 // cout<<2<<endl; 42 flag=1; 43 break; 44 } 45 next.step=first.step+1; 46 for(int i=0;i<4;i++){ 47 int a=first.x+_x[i]; 48 int b=first.y+_y[i]; 49 // cout<<a<<" "<<b<<endl; 50 while(check(a,b)){ 51 if(visited[a][b]==0){ 52 // cout<<3<<endl; 53 visited[a][b]=1; 54 next.x=a; 55 next.y=b; 56 Q.push(next); 57 } 58 a=a+_x[i]; 59 b=b+_y[i]; 60 } 61 } 62 } 63 if(flag==1)cout<<"yes"<<endl; 64 else 65 cout<<"no"<<endl; 66 67 } 68 int main(){ 69 int t; 70 scanf("%d",&t); 71 while(t--){ 72 memset(visited,0,sizeof(visited)); 73 scanf("%d%d",&m,&n); 74 for(int i=1;i<=m;i++){ 75 getchar(); 76 for(int j=1;j<=n;j++){ 77 scanf("%c",&mp[i][j]); 78 } 79 } 80 scanf("%d%d%d%d%d",&k,&xx,&yy,&x2,&y2); 81 G.x=yy; 82 G.y=xx; 83 G.step=-1; 84 visited[G.x][G.y]=1; 85 BFS(); 86 } 87 }
标签:ret tle iostream lib while ace tput sample pop
原文地址:http://www.cnblogs.com/Aa1039510121/p/6323657.html