zoukankan      html  css  js  c++  java
  • FZU 1894 志愿者选拔 单调队列

    训练赛的题……
    暴力一波明显超时……
    最近刚学stl 感觉是优先队列 但还是太会用……
    以后可以试一下优先队列……
    比赛之后百度了一下 发现是单调队列……
    看起来挺简单的 也算个模版题吧……
    总之思路就是维护一个单调队列……
    有用的的只有C G Q……
    那个长度最多是5的名字只用接着 根本没用……
    直接上代码……
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    struct p{
        int num,rp;
    }people[1000005];
    int main(){
        int T;
        scanf("%d",&T);
        while(T--){
            char s[10];
            int head=0,first=0,tail=-1,n=1;
            while(~scanf("%s",s)&&strcmp(s,"END")!=0){
                if(s[0]=='C'){
                    char name[6];
                    int val;
                    scanf("%s%d",name,&val);
                    while(tail>=head&&people[tail].rp<=val) tail--;
                    people[++tail].rp=val;
                    people[tail].num=n++;
                }
                else if(s[0]=='Q'){
                    while(tail>=head&&people[head].num<=first) head++;
                    if(tail>=head) printf("%d
    ",people[head].rp);
                    else printf("-1
    ");
                }
                else if(s[0]=='G') first++;
            }
        }
        return 0;
    }
     
  • 相关阅读:
    将u8BF7字符串转换为汉字
    ubuntu扩容
    python面试题
    OCR开源项目
    58到家数据库30条军规解读
    dvwa sql盲注教程
    python time模块详解,时间格式转换
    python正则表达式
    tr命令详解
    腐烂
  • 原文地址:https://www.cnblogs.com/general10/p/5414761.html
Copyright © 2011-2022 走看看