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 |
help,why i can't pass?? javaimport java.io.*; import java.util.*; /*Problem Id:1323 User Id:haroun Memory:4440K Time:312MS Language:Java Result:Wrong Answer*/ public class Main1{ public static void main(String args[]){ List l = new LinkedList(); Scanner s = new Scanner(System.in); int a1 = 0,a2=0 ; int lis = 0 ; Integer b ; boolean j=true; List l2 = new ArrayList(); String st ; int in = 1; Main1 m = new Main1(); while(j) { a1 = s.nextInt(); a2 = s.nextInt(); if(a1==a2 && a1==0) break; for(int i =0;i<a2;i++){ lis = s.nextInt(); b = Integer.valueOf(lis); l.add(b); } System.out.println(""); int x = m.judgeL(l,a1*a2); st = "case"+in+":"+x; in = in+1; l2.add(st); } Iterator il = l2.iterator(); while(il.hasNext()){ System.out.println((String)il.next()); } } /*先排序,从最小的开始处理,往后进行展望,看以后的累积的数是否都能大于前数列中的数,如果是, 则返回0,否则进行计算*/ public int judgeL(List l,int range){ Collections.sort(l); Iterator it = l.iterator(); int num = 0; Integer te1,te2; int temp1 = -1,temp2 = -1,temp3; while(it.hasNext()){ temp2 = temp1; num= num+1; te1 = (Integer)it.next(); temp1 = te1.intValue(); if(temp2!=-1 && temp2 != temp1){ //处理 temp3 = temp1 - temp2 - 1; if(temp3 >0) num = num - temp3; if(num < 0) num = 0; } } num = num +1; //要算最后一个数; temp3 = range - temp1; num = num - temp3; if(num<0) num = 0; return num; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator