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

各位大神看看,为什么C++的AC,Java一样的算法就WR???

Posted by 20114434 at 2012-08-13 15:10:40 on Problem 1442
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main{
	static PriorityQueue<Integer> p = new PriorityQueue<Integer>(11,new Comparator<Integer>() {
		public int compare(Integer o1, Integer o2) {
			return o2-o1;
		}
	});
	static PriorityQueue<Integer> q = new PriorityQueue<Integer>();
	static int[] a = new int[30005];
	static int[] b = new int[30005];
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			p.clear();q.clear();
			int m = cin.nextInt();
			int n = cin.nextInt();
			for(int i = 1; i <= m; i++)
				a[i] = cin.nextInt();
			for(int j = 1; j <= n; j++)
				b[j] = cin.nextInt();
			int i = 0, j = 1,k = 1;
			while(j<=n){
				if(i==b[j]){
					j++;
					if(p.size()<k){
						p.add(q.poll());
					}
					System.out.println(p.peek());
					k++;
				}else{
					i++;
					if(p.size()<k){
						q.add(a[i]);
						p.add(q.poll());
					}else if(p.peek()>a[i]){
						q.add(p.poll());
						p.add(a[i]);
					}else{
						q.add(a[i]);
					}
				}
			}
		}
	}
}

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