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 |
给的例子能通过,提交就WA,哪位大神帮忙看下~~#include <iostream> #include <string.h> #include <queue> #include <stdio.h> using namespace std; int visited[301][301]; int move[8][2]={{-1,-2},{-1,2},{1,-2},{1,2},{-2,-1},{-2,1},{2,-1},{2,1}}; struct node { int x,y; int steps; }start,end; int m; int check(int x,int y) { if(x>=0&&x<=m&&y>=0&&y<=m) { return 1; } return 0; } int bfs(int x,int y) { queue<node> que; node tmp,next; start.x=x; start.y=y; start.steps=0; memset(visited,0,sizeof(visited)); que.push(start); while(!que.empty()) { tmp=que.front(); visited[tmp.x][tmp.y]=1; que.pop(); for(int i=0;i<8;i++) { next.x=tmp.x+move[i][0]; next.y=tmp.y+move[i][1]; if(check(next.x,next.y)&&!visited[next.x][next.y]) { next.steps=tmp.steps+1; que.push(next); visited[next.x][next.y]=1; if(next.x==end.x&&next.y==end.y) { return next.steps; } } } } return 0; } int main() { //freopen("in.txt","r",stdin); int n,k; cin>>n; for(int i=0;i<n;i++) { cin>>m>>start.x>>start.y>>end.x>>end.y; k=bfs(start.x,start.y); cout<<k<<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