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

这种模拟题最好还是用类稳当。。破JAVA,又是100MS以上AC

Posted by yzhw at 2009-03-10 16:38:11 on Problem 1059
import java.io.*;
import java.util.Arrays;
class player
{
	private int pos=0;
	public int move(int num,int[] game)
	{
		if(pos+num>100) return 0;
		else 
		 {
			pos+=num;
			if(game[pos]==-1) return -1;
			else if(game[pos]==-2) return -2;
			else if(game[pos]>0)
			{
			 while(game[pos]!=0) pos=game[pos];
			}
		 }
		if(pos==100) return 1;
		else return 0;
	}
};
public class pku1059 {
	public static void main(String[] args) throws IOException{
		StreamTokenizer in=new StreamTokenizer(System.in);
		int count=0,num;
		int list[]=new int[1001];
		while(true)
		{
			int temp;
			in.nextToken();
			temp=(int)in.nval;
			if(temp!=0)  list[++count]=temp;
			else break;
		}
		//--------------------------------------------------------------
		
		while(true)
		{
		in.nextToken();
		num=(int)in.nval;
		if(num==0) break;
		int game[]=new int[101];
		player data[]=new player[num+1];
		for(int i=1;i<=num;i++) data[i]=new player();
		while(true)
		{
			int t1,t2;
			in.nextToken();
			t1=(int)in.nval;
			in.nextToken();
			t2=(int)in.nval;
			if(t1==0&&t2==0) break;
			else game[t1]=t2;
		}
		while(true)
		{
			int t;
			in.nextToken();
			t=(int)in.nval;
			if(t==0) break;
			else if(t>0) game[t]=-1;
			else game[-t]=-2;
		}
		//--------------------------------------------------------------
		boolean flag[]=new boolean[num+1];
		boolean exit=false;
		int pos=1;
		Arrays.fill(flag, true);
		while(pos<=count&&!exit)
		{
		  for(int i=1;i<=num&&!exit;i++)
		  {
			  if(flag[i])
			  {
				  int res=data[i].move(list[pos++], game);
				  while(res==-1) res=data[i].move(list[pos++], game);
				  if(res==-2) flag[i]=false;
				  else if(res==1)
				  {
					  System.out.println(i);
					  exit=true;
				  }
			  }
			  else flag[i]=true;
		  }
		}
	  }

	}

}

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