Fzu 1894 monotonous queue

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.