fzu 1894 單調隊列

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   使用   

http://acm.fzu.edu.cn/problem.php?pid=1894

 

 Problem 1894 志願者選拔Accept: 1328    Submit: 4200
Time Limit: 1500 mSec    Memory Limit : 32768 KB Problem Description

 

世博會馬上就要開幕了,福州大學組織了一次志願者選拔活動。
參加志願者選拔的同學們排隊接受面試官們的面試。參加面試的同學們按照先來先面試並且先結束的原則接受面試官們的考查。
面試中每個人的人品是主要考查對象之一。(提高人品的方法有扶老奶奶過街,不闖紅燈等)
作為主面試官的John想知道當前正在接受面試的同學隊伍中人品值最高的是多少。於是他請你幫忙編寫一個程式來計算。

 

 Input

 

輸入資料第一行為一整數T,表示有T組輸入資料。每組資料第一行為”START”,表示面試開始
接下來的資料中有三種情況:
  輸入 含義
1 C NAME RP_VALUE 名字為NAME的人品值為RP_VALUE的同學加入面試隊伍。(名字長度不大於5,0 <= RP_VALUE <= 1,000,000,000)
2 G 排在面試隊伍最前面的同學面試結束離開考場。
3 Q 主面試官John想知道當前正在接受面試的隊伍中人品最高的值是多少。
最後一行為”END”,表示所有的面試結束,面試的同學們可以依次離開了。
所有參加面試的同學總人數不超過1,000,000

 

 Output

 

對於每個詢問Q,輸出當前正在接受面試的隊伍中人品最高的值,如果當前沒有人正在接受面試則輸出-1。

 

 Sample Input2STARTC Tiny 1000000000C Lina 0QGQENDSTARTQC ccQ 200C cxw 100QGQC wzc 500QEND Sample Output10000000000-1200100500 Hint資料較大建議使用scanf,printf 不推薦使用STL ========================================有點坑爹,,,,,
#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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.