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 |
很神奇的 用队列哪里错了呢?关于队列的细节问题!#include <iostream> #include <algorithm> #include<queue> using namespace std; int array[400][400],vis[400][400]; int move[8][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-2,-1},{-1,-2}}; int main() { int i,n,t,x1,y1,x2,y2,x,y; while(scanf("%d",&t)!=-1) { while(t--) { queue<int> qu; while(!qu.empty()) qu.pop(); scanf("%d",&n); scanf("%d%d",&x1,&y1); scanf("%d%d",&x2,&y2); qu.push(x1); qu.push(y1); memset(array,0,sizeof(array)); memset(vis,0,sizeof(vis)); array[x1][y1]=0; while(!qu.empty()) { x=qu.front(); qu.pop(); y=qu.front(); qu.pop(); if(x==x2 && y==y2) break; for(i=0;i<8;i++) { if((x+move[i][0]>=0)&&(x+move[i][0]<n)&&(y+move[i][0]>=0)&&(y+move[i][1]<n)&&vis[x+move[i][0]][y+move[i][1]]==0) { qu.push(x+move[i][0]); qu.push(y+move[i][1]); array[x+move[i][0]][y+move[i][1]]=array[x][y]+1; vis[x+move[i][0]][y+move[i][1]]=1; } } } cout<<array[x][y]<<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