HDU1873(队列应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873
package D0725;import java.util.*;public class HDU1873 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n;LinkedList<Patient> list1;LinkedList<Patient> list2;LinkedList<Patient> list3;while (sc.hasNext()) {n = sc.nextInt();list1 = new LinkedList<Patient>();list2 = new LinkedList<Patient>();list3 = new LinkedList<Patient>();int id = 1;while (n-- > 0) {String str = sc.next();// inif (str.charAt(0) == 'I') {int docid = sc.nextInt();int priority = sc.nextInt();Patient p = new Patient(id++, docid, priority);if (docid == 1) {list1.add(p);Collections.sort(list1);} else if (docid == 2) {list2.add(p);Collections.sort(list2);} else {list3.add(p);Collections.sort(list3);}} else {//outint docid = sc.nextInt();if (docid == 1) {if (list1.isEmpty())System.out.println("EMPTY");elseSystem.out.println(list1.poll().id);} else if (docid == 2) {if (list2.isEmpty())System.out.println("EMPTY");elseSystem.out.println(list2.poll().id);} else {if (list3.isEmpty())System.out.println("EMPTY");elseSystem.out.println(list3.poll().id);}}}}}}class Patient implements Comparable<Patient> {public int docId;public int priority;public int id;public Patient(int id, int docId, int priority) {this.id = id;this.docId = docId;this.priority = priority;}@Overridepublic int compareTo(Patient o) {if (this.priority >= o.priority)return -1;return 1;}}