Click to open Hangzhou Electric 1873
Problem description to see a doctor in line this is the common sense that the Earth people know.
However, after careful observation of 0068, he found that the hospital lined up or there are fastidious. 0068 hospitals went to the hospital with three doctors (sweat, so little) at the same time to see a doctor. And the doctor's illness has severity, so can not be based on a simple first-served principle. So hospitals prescribe 10 different priorities for each condition. Level 10 has the highest priority and level 1 has the lowest priority. When a doctor is in the hospital, he or she chooses a person with the highest priority in his or her team for treatment. If you encounter two patients with the same priority, select the first patient to queue up.
Now ask you to help the hospital simulate the doctor's procedure.
Input data contains multiple sets of tests, please process to the end of the file.
The first row of each group of data has a positive integer N (0<n<2000) indicating the number of events that occurred.
Next there are n rows representing the events that occurred.
There are two types of events:
1: "In a B", indicates that a patient with priority B requires doctor A to diagnose and treat. (0<a<=3,0<b<=10)
2: "Out A", indicating that doctor A has performed a diagnosis and treatment, the patient is discharged. (0<a<=3)
Output for each "out A" event, print the ID number of the person being diagnosed in a row. If no patient is required to diagnose the event, the output is "EMPTY".
The ID of the person to be diagnosed is defined as: in a set of tests, the "in a B" event occurs k times, the patient ID that comes in is K. Numbering starts from 1.
Sample Input
7IN 1 1IN 1 2OUT 1OUT 2IN 2 1OUT 2OUT 12IN 1 1OUT 1
Sample Output
2empty311
train of thought: Test instructions already very clear, can use the queue to do this problem. Because the beginner queue, not very deep understanding, this question may also be what they call the priority queue. According to the requirements of the topic, can apply for three queues, respectively, to operate. Priority is also given to each queue, so you can prioritize the data in the queue first when you are out of the queue. Just here do not know why use priority queue is dead a not past, with the normal queue on the AC. It's really!!!!!!. (There are several groups of helpful test data available later)
Note : 1, the requirements of the output is not priority, although the wrong oh, but the number of people who came in the serial numbers
2, also the priority to sort, do not make mistakes: find the current output of the person's priority, and then exchange, this is wrong.
Normal queue (can AC):
Import Java.util.scanner;public class P1873_2 {public static void main (string[] args) {Scanner sc=new Scanner (system.in); String S;int Priority,num,count; Personlqueue[] Loopqueue=new personlqueue[4];//applies for three queues, here 0 without while (Sc.hasnext ()) {int n=sc.nextint (); Count=0;for ( int i=1;i<4;i++) {loopqueue[i]=new personlqueue ();} for (int i=0;i<n;i++) {s=sc.next (); if (S.charat (0) = = ' I ') {//If in then directly to the queue can Count++;num=sc.nextint ();p riority= Sc.nextint (); Ppersonl p=new ppersonl (count,priority);//This is a ppersonl class, which is to store everyone's priority, and there is the number of inputs (which is why you have to build a separate class) Loopqueue[num]. Add (P);//queue}else{//out Team Num=sc.nextint (); int A=loopqueue[num].pop (); if (a==0) {System.out.println ("EMPTY");} Else{system.out.println (a);}}}}} Class Ppersonl{int priority;//priority int count;//person's serial number (number of persons), that is, the public ppersonl required to be output (int count, int priority) { this.count=count;this.priority=priority;}} Class Personlqueue{int end;final int FRONT = 0; Ppersonl[] Personl;public personlqueue () {end = 0;personl=new ppersonl[10000];} public void Add (Ppersonl p) {//Queue Personl[end] = p;end++;} public int IsEmpty () {//Determines whether it is empty, there is no egg in this question with if (end<=0) {return 0;} return 1;} public int pop () {//Out of queue if (end<=0) {return 0;} Sort ();//The priority is sorted int p = personl[front].count;if (end>1) {//Team first out team, then the next one to fill up for (int i=0;i<end;i++) {Personl[i] = PERSONL[I+1];}} End--;return p;} private void Sort () {//bubble sort for (int. i=0;i<end-1;i++) {for (int j=0;j<end-i-1;j++) {if (personl[j].priority< personl[j+1].priority) {ppersonl temp=personl[j];p ersonl[j]=personl[j+1];p ersonl[j+1]=temp;}}}}
Loop Queue (WA):
Package Xjj;import Java.util.scanner;public class P1873 {public static void main (string[] args) {Scanner sc=new Scanner (Sy stem.in); String S;int Priority,num,count; Circlingqueue[] Loopqueue=new circlingqueue[4];while (Sc.hasnext ()) {int n=sc.nextint (); count=0;for (int i=1;i<4;i + +) {loopqueue[i]=new circlingqueue (n);} for (int i=0;i<n;i++) {s=sc.next (); if (S.charat (0) = = ' I ') {count++;num=sc.nextint ();p riority=sc.nextint (); Personl p=new personl (count,priority); Loopqueue[num].add (P);} Else{num=sc.nextint (); int A=loopqueue[num].pop (); if (a==0) {System.out.println ("EMPTY");} Else{system.out.println (a);}}}}} Class Personl{int Priority;int count;public personl (int count, int priority) {this.count=count;this.priority=priority;}} Class Circlingqueue{int Front;int end,n; Personl[] personl;public circlingqueue (int n) {Front =0;end = 0;this.n=n;personl=new PERSONL[THIS.N];} public void Add (Personl p) {Personl[end] = P;end = (end+1)%n;} public int IsEmpty () {return front==end? 0:1;} public int Pop () {if (IsEmpty ()==0) {return 0;} sort (); int p = Personl[front].count;front = (front+1)%n;return p;} private void sort () {for (int. i=front;i<end-1;i++) {for (int j=front;j<end-i-1;j++) {if (personl[j].priority< personl[j+1].priority) {personl temp=personl[j];p ersonl[j]=personl[j+1];p ersonl[j+1]=temp;}}}}
Test data:
7
In 1 10
In 1 5
In 1 8
In 1 4
Out 1
Out 1
Out 1
Results: 1 3 2
12
In 1 10
In 1 4
In 1 4
In 1 5
In 1 4
In 1 4
Out 1
Out 1
Out 1
Out 1
Out 1
Out 1
Results: 1 4 2 3 5 6
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu1873 (Waiting for a doctor to queue) The loop is killing me.