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..??

Posted by Steinersp at 2006-12-26 13:34:13 on Problem 2726
import java.io.*;
import java.util.*;

class Main {
	
	static boolean candidate[];
	static int distance[];
	static int cost[];
	
	public static int nhotel() {
		
		for (int i = 0; i < candidate.length; i ++)
			candidate[i] = true;
		
		for (int i = 0; i < cost.length - 1; i ++) {
			
			if (!candidate[i])
				continue;
			
			for (int j = i + 1; j < cost.length; j ++) {
				
				if (distance[j] >= distance[i] && cost[j] > cost[i])
					candidate[j] = false;
				else if (cost[j] >= cost[i] && distance[j] > distance[i])
					candidate[j] = false;
			}
		}
		
		int count = 0;
		for (int i = 0; i < candidate.length; i ++)
			if (candidate[i])
				count ++;
		return count;
	}
	
	public static void main(String args[]) throws IOException {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int n;
		StringTokenizer token;
		
		while ((n = new Integer(in.readLine())) != 0) {
			
			candidate = new boolean[n];
			distance = new int[n];
			cost = new int[n];
			
			for (int i = 0; i < n; i ++) {
				
				token = new StringTokenizer(in.readLine());
				distance[i] = new Integer(token.nextToken());
				cost[i] = new Integer(token.nextToken());
			}
			out.println(nhotel());
			out.flush();
		}
	}
}

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