题意

分析

极似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. jqGrid有关问题 小知识点

    为每一行添加查看按钮  并且   调整行高 gridComplete:function(taskDatas){ //在此事件中循环为每一行添加修改和删除链接 $( ".autotip&quo ...

  2. 如何把js的循环写成异步的

    针对这里的问题:深入理解node.js异步编程:基础篇https://cnodejs.org/topic/533d6edbc2621e680800e0ea 这一节有一个代码:###4.1 Node.j ...

  3. 解决margin重叠的问题

    margin重叠有两种情况: 1.兄弟级的垂直块之间,margin这个属性上下边距,会发生重叠的情况 解决办法:float浮动或display:inline-block 2 .父子级的块之间,子级的上 ...

  4. ACM赛前准备——模板(排版篇)

    ACM赛前准备--模板(排版篇) 更新 前言 效果演示 封面 目录页 模板页(不分栏) 模板页(分栏) 结果文件 快速使用 准备工作 安装TexLive (可选)安装minted包 创建模板 文件结构 ...

  5. json.dump()和json.load()

    import json,time # save data to json file def store(data): with open('data.json', 'w') as fw: # 将字典转 ...

  6. [原][译][osgearth]API加载地球(OE官方文档翻译)

    原文参考:http://docs.osgearth.org/en/latest/developer/maps.html#programmatic-map-creation 本人翻译水平有限... 加载 ...

  7. How to Restore “TrustedInstaller” as Default Owner of a File

    type NT SERVICE\TrustedInstaller in "Enter the object name to select" text box http://www. ...

  8. 简述 JPA 与 Spring Data JPA 与 Hibernate

    1.JPA是什么?以及相关概述 JPA的是 Java Persistence API 的简写,是Sun官方提出的一种ORM规范! Sun提出此规范有2个原因: 1.简化现有Java EE和Java S ...

  9. python运行错误---TabError: Inconsistent use of tabs and spaces in indentation

    本文转载于:http://blog.csdn.net/sinat_36384705/article/details/71155379 首先这个错误的意思是:在缩进的时候,使用了错误的空格和tab 我使 ...

  10. 操作ACCESS数据库,报INSERT INTO 语句的语法错误

    错误类型:Microsoft JET Database Engine (0x80040E14)INSERT INTO 语句的语法错误. 有时候非常郁闷,明明看起来自己的语句没错,为什么还是报错呢?其实 ...