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

晕啊~~~这里这里的数据全部通过还是WA,牛人指点下!!谢谢(附数据附代码(java))

Posted by hualixuqu at 2010-12-12 17:13:22 on Problem 1029
数据:
3 2
1 1 2
<
1 2 3
<
0

3 2
1 1 2
>
1 1 3
>
1

5 1
2 1 2 3 4
=
5

4 3
2 1 2 3 4
<
2 1 3 2 4
<
1 2 4
=
1

5 3
2 1 3 2 4
>
2 3 5 2 4
>
1 1 4
>
4

5 3
2 1 3 2 4
>
2 3 5 2 4
>
1 1 4
=
0

7 3
2 1 2 3 4
<
2 1 5 3 4
<
3 3 4 1 7 6 5
<
1

可是可是还是WA  不解啊!
代码:
import java.util.Scanner;

public class Main{
	public static void main(String[] args)throws Exception{
		Scanner cin=new Scanner(System.in);
		int ToT=2,ToTnum=0,result=0;
		int k=0;
		int coinNum=cin.nextInt();
		int[] id=new int[coinNum];
		String[] idString=new String[coinNum];
		for(int i=0;i<id.length;i++){
			id[i]=0;
			idString[i]="null";
		}
		int weightings=cin.nextInt();
		cin.nextLine();
		while(cin.hasNext()){
			k=k+1;
			String pan=cin.nextLine();
			String[] coin=pan.split(" ");
			int nOPan=Integer.valueOf(coin[0]);
			String c=cin.next();
			if(c.equals("=")){
				for(int i=0;i<2*nOPan;i++){
					id[(int)coin[i+1].charAt(0)-49]=1;
				}
			}
			if(c.equals("<") || c.equals(">")){
				ToT=ToT+1;
				for(int i=0;i<2*nOPan;i++){
					if(id[(int)coin[i+1].charAt(0)-49]!=1){
						String temp=c.equals("<")? "heavy" : "light";
						String temp2=c.equals("<")? "light" : "heavy";
						id[(int)coin[i+1].charAt(0)-49]=ToT;
						if(i<nOPan){
							if(idString[(int)coin[i+1].charAt(0)-49]==temp2)						
								id[(int)coin[i+1].charAt(0)-49]=1;
							else
								idString[(int)coin[i+1].charAt(0)-49]=temp;
						}
						else{
							if(idString[(int)coin[i+1].charAt(0)-49]==temp)						
								id[(int)coin[i+1].charAt(0)-49]=1;
							else
								idString[(int)coin[i+1].charAt(0)-49]=temp2;
						}
					}
				}
				for(int i=0;i<id.length;i++){
					if(id[i]!=ToT)id[i]=1;
				}
			}
			cin.nextLine();
			if(k==weightings)break;
		}
		for(int i=0;i<id.length;i++){
			if(id[i]==ToT || id[i]==0){
				ToTnum=ToTnum+1;
				result=i+1;
			}
		}
		System.out.println(ToTnum==1 ? result : 0);
	}
}

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