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

Why WA? HELP!!!!!!!!!!

Posted by smxysmxy at 2008-09-19 23:13:27 on Problem 1323
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:
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