Experiment 10: Problem C: STL -- heap-type automatic machine and stl Automatic Machine
The command POP id t is incorrect. Only the first element of the queue is output, instead of the first element. Question, Because I Output Limit Exceed50 % 7 times .....
Home |
Web Board |
ProblemSet |
Standing |
Status |
Statistics |
Problem C: STL -- Heh-shaped Automatic Machine Problem C: STL -- Heh-shaped automatic machine Time Limit: 8 Sec Memory Limit: 128 MB
Submit: 1890 Solved: 731
[Submit] [Status] [Web Board] Descriptionxiaofei recently developed a heap-type automatic machine that can process n queues at the same time. The queue number is 1. n. A m operation is given to simulate the working status of the automatic machine. The first line has two integers n, m (1 ≤ n, m ≤ 10,000), indicating that the automatic processing of n queues, then m lines each line of an operation command. The format of each command is as follows:
Command |
Instructions |
INIT |
Initialize the automatic machine. At this time, all queues are cleared. |
PUSH id val t |
Add the t integer val to the end of the queue with the id. |
POP id t |
The first t first element of the queue whose id is output and deleted. If the queue is empty, the output is "NULL ". |
In each instruction, the id number is in 1. n, and the val value range is-231 ~ 231. Input data to ensure that the first command of the operation is INIT.
Input
There are multiple groups of input data in this question. You must process the data until the EOF.
Output
Output one row of results for each POP command in the input data in sequence.
Sample Input3 12 init push 1 100 1POP 2 1 PUSH 3 300 1 PUSH 1 200 1 PUSH 2-5 1POP 2 1 PUSH 2-10 1POP 1 1 1 init push 1 7 1POP 1 1 Sample outputNULL-51007HINT
It is easy to solve with STL queue
Append Code [Submit] [Status] [Web Board]
Please refer to the following link for more information:
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin: admin
#include<iostream>#include<queue>#include<string>#define MAX 10002using namespace std;int main(){ queue<int>q[MAX]; int n,m; string c; int id,val; while(cin>>n) { cin>>m; for(int i=0;i<m;i++) { cin>>c; if(c=="INIT") { for(int j=1;j<=m;j++) while(!q[j].empty()) q[j].pop(); } else if(c=="PUSH") { int t; cin>>id>>val>>t; while(t--) q[id].push(val); } else if(c=="POP") { int t; cin>>id>>t; if(q[id].empty()) cout<<"NULL"<<endl; else { queue<int> nq; cout<<q[id].front()<<endl; q[id]=nq; } } } } return 0;}