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 |
Why WA? HELP!!!!!!!!!!import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int n,m;int length;int result;int c=0;int i,j; while(true){ c++; m=scanner.nextInt(); n=scanner.nextInt(); if(m==0&&n==0)break; length=m*n; int[] a=new int[n]; int[] b=new int[n]; result=0; for(i=0;i<n;i++){a[i]=scanner.nextInt();b[i]=0;} java.util.Arrays.sort(a); //for(int i=0;i<n;i++)System.out.print(b[i]+" "); //System.out.println(); for(i=length;i>=length-n+1;i--){ for(j=n-1;j>=0;j--){ if(a[j]==i){b[length-i]=1;} if(a[j]<i){ break; } } } //for(int i=0;i<n;i++)System.out.print(b[i]+" "); //System.out.println(); outer: for(i=0;i<n;i++){ if(b[i]==0){ for(j=i+1;j<n;j++){ if(b[j]==1){ b[j]=-1; break; } if(j==n-1&&b[j]==0){ break outer; } } } } for(i=0;i<n;i++){ //System.out.print(b[i]+" "); if(b[i]==1) result+=b[i]; } System.out.println("Case "+c+": "+result); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator