Problem 1894 志愿者选拔
Accept: 1630 Submit: 5041
Time Limit: 1500 mSec Memory Limit : 32768 KB
Problem Description
Input
输入 | 含义 | |
1 | C NAME RP_VALUE | 名字为NAME的人品值为RP_VALUE的同学加入面试队伍。(名字长度不大于5,0 <= RP_VALUE <= 1,000,000,000) |
2 | G | 排在面试队伍最前面的同学面试结束离开考场。 |
3 | Q | 主面试官John想知道当前正在接受面试的队伍中人品最高的值是多少。 |
Output
Sample Input
2STARTC Tiny 1000000000C Lina 0QGQENDSTARTQC ccQ 200C cxw 100QGQC wzc 500QEND
Sample Output
10000000000-1200100500
Hint
数据较大建议使用scanf,printf 不推荐使用STL
Source
福州大学第七届程序设计竞赛
这种题,各种数据结构能过,不过队列最简单
ac代码
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int q[1000010],rp[1000010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int size=-1;
int first,rear,op;
first=op=0;
rear=-1;
char cc[5];
scanf("%s",cc);
while(scanf("%s",cc)!=EOF)
{
if(strcmp(cc,"END")==0)
break;
char name[10];
if(cc[0]=='C')
{
size++;
scanf("%s%d",name,&rp[size]);
for(;first<=rear&&rp[size]>=rp[q[rear]];rear--);
q[++rear]=size;
}
else
if(cc[0]=='G')
{
op++;
for(;first<=rear&&q[first]<op;first++);
}
else
{
if(first<=rear)
{
printf("%d\n",rp[q[first]]);
}
else
printf("-1\n");
}
}
}
}