Http://acm.fzu.edu.cn/problem.php? PID = 1, 1894
Problem 1894 volunteer SelectionAccept: 1328 submit: 4200
Time Limit: 1500 msec memory limit: 32768 kb Problem Description
The World Expo is about to kick off. Fuzhou University organized a volunteer selection activity.
The students who participated in the volunteer selection queue for interviews with the interviewers. The students who participate in the interview follow the principle of first-first interview and first-end interview to accept the interviewer's examination.
The character of each person in the interview is one of the main subjects. (The methods to improve the character include helping the old grandmother pass through the street, not running the red light, etc)
John, as the main interviewer, wants to know the maximum number of students currently being interviewed. So he asked you to write a program for computation.
Input
The first act of the input data is an integer T, indicating that there is a T group of input data. The first act of data in each group is "start", indicating the start of the interview.
There are three situations in the following data:
| |
Input |
Description |
| 1 |
C Name rp_value |
Students with the character value rp_value whose name is name join the interview team. (The name length is not greater than 1,000,000,000 <= rp_value <=) |
| 2 |
G |
Students at the top of the interview team leave the test room after the interview. |
| 3 |
Q |
The main interviewer John wants to know the maximum number of people in the current Interview Team. |
The last line is "end", indicating that all the interviews are completed and the students can leave.
The total number of participants in the interview shall not exceed 1,000,000
Output
For each Q & A query, the highest ranking of the teams currently in the interview is output. If no one is currently in the interview,-1 is output.
Sample input2startc tiny 1000000000c Lina 0 qgqendstartqc ccq 200C cxw 100 qgqc wzc 500 qend sample Output10000000000-1200100500 hint Data Large recommended use scanf, we do not recommend that you use STL ============================================ ====== a bit difficult ,,,,,
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>typedef struct Node{ int num; char name[10]; int data;}queue;queue f[1000010];int main(){ int n,m,i,j,tail,head; scanf("%d",&n); queue tmp; while(n--) { char cur[10]; int Num=0,count=0; head=0,tail=-1; while(scanf("%s",cur)!=EOF) { if(cur[0]==‘C‘) { scanf("%s%d",tmp.name,&tmp.data); tmp.num=++Num; while(head<=tail && f[tail].data<tmp.data) { tail--; } f[++tail]=tmp; } if(cur[0]==‘S‘)continue; if(cur[0]==‘E‘)break; if(cur[0]==‘Q‘) { while(tail>=head && f[head].num<=count) { head++; } if(head>tail)printf("-1\n"); else printf("%d\n",f[head].data); } if(cur[0]==‘G‘) { count++; } } } return 0;}View code