题意

分析

极似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. eclipse中gradle插件安装

    help===>install software===>http://download.eclipse.org/buildship/updates/e46/releases/2.x/

  2. java -- JVM的符号引用和直接引用

    在JVM中类加载过程中,在解析阶段,Java虚拟机会把类的二级制数据中的符号引用替换为直接引用. 1.符号引用(Symbolic References): 符号引用以一组符号来描述所引用的目标,符号可 ...

  3. Vue学习笔记之Webpack介绍

    在这里我仅仅的是对webpack做个讲解,webpack这个工具非常强大,解决了我们前端很繁琐的一些工具流程繁琐的事情.如果感兴趣的同学,简易还是看官网吧. 中文链接地址:https://www.we ...

  4. PHP Fatal error: Uncaught Error: Call to undefined function pcntl_fork().. 开启php pcntl扩展实现多进程

    在使用函数pcntl_fork()时报错  Fatal error: Uncaught Error: Call to undefined function pcntl_fork()....,原因是没有 ...

  5. 20145336张子扬 《网络对抗》逆向及bof基础

    20145336张子扬 <网络对抗>逆向及bof基础 学习知识点 缓冲区溢出 缓冲区溢出 一种非常普遍.非常危险的漏洞,在各种操作系统.应用软件中广泛存在.利用缓冲区溢出攻击,可以导致程序 ...

  6. java实验五20145204

    java实验 Tcp传输 实验内容 运行代码一人服务器,一人客户端. 下载加解密代码,先编译运行代码,一人加密一人解密,适当修改代码. 集成代码,一人加密后通过TCP发送,加密使用AES或DES,AE ...

  7. 20145311王亦徐 实验三 "敏捷开发与XP实践"

    20145311王亦徐 实验三 "敏捷开发与XP实践"程序设计过程 实验内容 使用 git 上传代码 使用 git 相互更改代码 实现代码的重载 git 上传代码 查看代码是否有修 ...

  8. 经查-- git使用报错及解决办法

    git push 错误 error: failed to push some refs to 'git@github.com:charblus/ ...' 本地和远程的文件应该合并后才能上传本地的新文 ...

  9. Python3基础 try-except 几个异常采取同样的处理方法

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. UVa 11489 整数游戏

    https://vjudge.net/problem/UVA-11489 题意: 给出一个数字串n,两个人轮流从中取出一个数字,要求每次取完之后剩下的数是3的倍数,不能取数者输. 思路: 要想取掉一个 ...