题意

分析

极似UVa11995 I Can Guess the Data Structure!

模拟即可,时间复杂度(……)\(O(n \log n)\)

旁边的L君:这题有两个坑点,我被卡了一次。

然而我一次就AC了。

旁边的L君:一个坑点是空栈,一个是输出格式

代码

#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#include<cassert>
#define rg register
#define il inline
#define co const
#pragma GCC optimize ("O0")
using namespace std;
template<class T> il T read()
{
    T data=0;
    int w=1;
    char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
        data=10*data+ch-'0',ch=getchar();
    return data*w;
}
template<class T> il T read(T&x)
{
    return x=read<T>();
}
typedef long long ll;
const int INF=0x7fffffff;

stack<int>S;
queue<int>Q;
priority_queue<int>H;

int main()
{
  freopen("qu.in","r",stdin);
  freopen("qu.out","w",stdout);
    int n=read<int>();
    bool is=1,iq=1,ih=1;
    for(int i=1;i<=n;++i)
    {
        int opt=read<int>(),v=read<int>();
        if(opt==1)
        {
            if(is)
            {
                S.push(v);
            }
            if(iq)
            {
                Q.push(v);
            }
            if(ih)
            {
                H.push(v);
            }
        }
        else
        {
            if(is)
            {
                if(S.empty())
                    is=0;
                else if(S.top()!=v)
                    is=0;
                else
                    S.pop();
            }
            if(iq)
            {
                if(Q.empty())
                    iq=0;
                else if(Q.front()!=v)
                    iq=0;
                else
                    Q.pop();
            }
            if(ih)
            {
                if(H.empty())
                    ih=0;
                else if(H.top()!=v)
                    ih=0;
                else
                    H.pop();
            }
        }
    }
    printf("%s\n",is?"YES":"No");
    printf("%s\n",iq?"YES":"No");
    printf("%s\n",ih?"YES":"No");
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}

test20181024 qu的更多相关文章

  1. 12563 Jin Ge Jin Qu hao

    • Don’t sing a song more than once (including Jin Ge Jin Qu). • For each song of length t, either si ...

  2. UVA12563-Jin Ge Jin Qu hao(动态规划基础)

    Problem UVA12563-Jin Ge Jin Qu hao Accept: 642  Submit: 7638Time Limit: 3000 mSec Problem Descriptio ...

  3. uVa 12563 Jin Ge Jin Qu

    分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...

  4. UVA - 12563 Jin Ge Jin Qu hao (01背包)

    InputThe first line contains the number of test cases T (T ≤ 100). Each test case begins with two po ...

  5. hanzi 全拼音 qu de

    Function pinyin(ByVal mystr As String, Optional types As Byte = 0) As StringDim temp   As String, i ...

  6. UVA Jin Ge Jin Qu hao 12563

    Jin Ge Jin Qu hao (If you smiled when you see the title, this problem is for you ^_^) For those who ...

  7. 12563 - Jin Ge Jin Qu hao——[DP递推]

    (If you smiled when you see the title, this problem is for you ^_^) For those who don’t know KTV, se ...

  8. UVA12563Jin Ge Jin Qu hao(01背包)

    紫书P274 题意:输入N首歌曲和最后剩余的时间t,问在保证能唱的歌曲数目最多的情况下,时间最长:最后必唱<劲歌金曲> 所以就在最后一秒唱劲歌金曲就ok了,背包容量是t-1,来装前面的歌曲 ...

  9. qu

    离骚 (3481人评分) 8.5   朝代:先秦 作者:屈原 原文: 帝高阳之苗裔兮,朕皇考曰伯庸.摄提贞于孟陬兮,惟庚寅吾以降.皇览揆余初度兮,肇锡余以嘉名:名余曰正则兮,字余曰灵均.纷吾既有此内美 ...

随机推荐

  1. java Pattern(正则)类

    Pattern的静态方法matches 用于快速匹配字符串,该方法适合用于只匹配一次,且匹配全部字符串. Boolean b=Pattern.matches("^((13[0-9])|(15 ...

  2. BZOJ 5102: [POI2018]Prawnicy

    考虑最优解的集合中一定有一个$l$最大的,我们就去枚举左端点,把所有$l$小于等于它的全丢进堆里,取前$k$个即可. #include <bits/stdc++.h> using name ...

  3. 计算机bit是什么意思

    bit是计算机中数据的最小单位,即二进制位,数字0和1 一个字节是八位(8个0和1 或 1 组成的一串二进制) 一个字是16位,等于2个字节 用八位二进制表示的字符叫单字节字符, 用16位二进制数表示 ...

  4. linux内核启动时报错ubi0 error: validate_ec_hdr: bad VID header offset 256, expected 64

    1.详细错误报告如下: ubi0 error: validate_ec_hdr: bad VID header offset 256, expected 64 ubi0 error: validate ...

  5. 百度语音识别vs科大讯飞语音识别

    一.结果 从笔者试验的结果来看,科大讯飞的语音识别技术远超百度语音识别 二.横向对比   科大讯飞语音识别 百度语音识别 费用 各功能的前5小时免费 全程免费 转换精准率 非常高 比较低 linux ...

  6. Educational Codeforces Round 47 D

    Let's call an undirected graph $G=(V,E)$ relatively prime if and only if for each edge $(v,u)∈E$ $GC ...

  7. Anaconda ubuntu16.04 Cuda 8.0安装pytorch

    Pytorch 安装 Pytorch安装真的太让人省心了,在anaconda的环境下进行安装,只需要一个命令 具体命令请查看官网pytorch 找到适合你的版本进行安装 本机环境: anaconda3 ...

  8. python 计算字典value值的和

    my_dict = {,,} print(sum(my_dict.values()))

  9. taglist-plus 安装使用

    taglist 可以查看文件中的 类,函数,变量等信息. 在.vimrc中添加: Plugin 'taglist-plus' 然后打开vim编辑器 PluginInstall 使用: 打开taglis ...

  10. 关于 Flutter的Button按钮没有高度设置

    flutter 里面 RaisedButton.FloatingActionButton.FlatButton.OutlineButton 中四个button都无高度设置,如下用RaisedButto ...