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 |
Time Limit... I don't know what more to do... help meimport 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; if (distance[j] <= distance[i] && cost[j] < cost[i]) { candidate[i] = false; break; } if (distance[j] < distance[i] && cost[j] <= cost[i]) { candidate[i] = false; break; } } } 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 FileReader("hotel.txt")); 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator