Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

搞掂了,过了~自己低级错误

Posted by qq361119908 at 2009-09-10 20:47:27 on Problem 1915
In Reply To:java用LinkedList为什么会WA啊~ Posted by:qq361119908 at 2009-09-10 20:41:20
> import java.util.*;
> public class a1915
> {
> 	int beginX;
> 	int beginY;
> 	int endX;
> 	int endY;
> 	int n;
> 	int k;
> 	int[][] num;
> 	int[][] map;
> 	LinkedList<Integer> v1;
> 	LinkedList<Integer> v2;
> 	public a1915()
> 	{
> 		Scanner r=new Scanner(System.in);
> 		k=r.nextInt();
> 		while (k>0)
> 		{
> 			n=r.nextInt();
> 			map=new int[n][n];
> 			num=new int[n][n];
> 			beginX=r.nextInt();
> 			beginY=r.nextInt();
> 			endX=r.nextInt();
> 			endY=r.nextInt();
> 			v1=new LinkedList<Integer>();
> 			v2=new LinkedList<Integer>();
> 			v1.add(beginX);
> 			v2.add(beginY);
> 			map[beginX][beginY]=1;
> 			while(v1.isEmpty()!=true&&v2.isEmpty()!=true)
> 			{
> 				int X=v1.poll();
> 				int Y=v2.poll();
> 				bfs(X,Y);
> 			}
> 			System.out.println(num[endX][endY]);
> 			k--;
> 		}
> 	}
> 	public void bfs(int x,int y)
> 	{
> 		if (x==endX&&y==endY)
> 		{
> 			return;
> 		}
> 		if (x-2>=0&&y-1>=0&&map[x-2][y-1]==0)
> 		{
> 			num[x-2][y-1]=num[x][y]+1;
> 			map[x-2][y-1]=1;
> 			v1.add(x-2);
> 			v2.add(y-1);
> 		}
> 		if (x-2>=0&&y+1<n&&map[x-2][y+1]==0)
> 		{
> 			num[x-2][y+1]=num[x][y]+1;
> 			map[x-2][y+1]=1;
> 			v1.add(x-2);
> 			v2.add(y+1);
> 		}
> 		if (x-1>=0&&y-2>=0&&map[x-1][y-2]==0)
> 		{
> 			num[x-1][y-2]=num[x][y]+1;
> 			map[x-1][y-2]=1;
> 			v1.add(x-1);
> 			v2.add(y-2);
> 		}
> 		if (x-1>=0&&y+2<n&&map[x-1][y+2]==0)
> 		{
> 			num[x-1][y+2]=num[x][y]+1;
> 			map[x-1][y+2]=1;
> 			v1.add(x-1);
> 			v2.add(y+2);
> 		}
> 		if (x+1<n&&y-2>=0&&map[x+1][y-2]==0)
> 		{
> 			num[x+1][y-2]=num[x][y]+1;
> 			map[x+1][y-2]=1;
> 			v1.add(x+1);
> 			v2.add(y-2);
> 		}
> 		if (x+1<n&&y+2<n&&map[x+1][y+2]==0)
> 		{
> 			num[x+1][y+2]=num[x][y]+1;
> 			map[x+1][y+2]=1;
> 			v1.add(x+1);
> 			v2.add(y+2);
> 		}
> 		if (x+2<n&&y-1>=0&&map[x+2][y-1]==0)
> 		{
> 			num[x+2][y-1]=num[x][y]+1;
> 			map[x+2][y-1]=1;
> 			v1.add(x+2);
> 			v2.add(y-1);
> 		}
> 		if (x+2<n&&y+1<n&&map[x+1][y+1]==0)
> 		{
> 			num[x+2][y+1]=num[x][y]+1;
> 			map[x+2][y+1]=1;
> 			v1.add(x+1);
> 			v2.add(y+1);
> 		}
> 
> 	}
> 	public static void main(String[] args) 
> 	{
> 		a1915 t=new a1915();
> 	}
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator