题目链接

luogu P3952 时间复杂度

题解

直接模拟即可

注意不要直接return

我真是naive

......

代码

#include<map>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for(int a = b;a <= c;++ a)
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9') { if(c == '-') f =- 1;c = gc;}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
char s[10007];
#define len(x) strlen(x + 1)
std::map<char,bool>mp;
std::stack<char>stk;
std::map<char,bool> cant;
std::map<char,bool> isnot;
void solve() {
int L = read();
int l;
scanf("%s",s + 1);
l = len(s);
int ben = 0;
bool fs = false;
rep(i,1,l) {
if(s[i] == 'n') fs = true;
if(s[i] <= '9' && s[i] >= '0') ben = ben * 10 + s[i] - '0';
}
int belnow = 0,bel = 0;
int flag = 0;
bool QAQ = false;
while(L --) {
scanf("%s",s + 1);
if(s[1] == 'F') {
int now = 0,nowto = 0;
char t,p = '%';
rep(T,1,3) {
if(T == 1) {
scanf("%s",s + 1);
if(mp[s[1]]) {
//puts("ERR");
QAQ = true;
//continue;
}
mp[s[1]] = 1;
t = s[1];
stk.push(s[1]);
}
if(T == 2) {
scanf("%s",s + 1);
if(s[1] < '0' || s[1] > '9') {
p = s[1];
continue;
}
l = len(s);
rep(i,1,l)
if(s[i] <= '9' && s[i] >= '0') now = now * 10 + s[i] - '0';
}
if(T == 3) {
scanf("%s",s + 1);
l = len(s);
if(l == 1 && (s[1] > '9' || s[1] < '0')) {
if(s[1] == p) continue;
belnow ++;
if(!flag) bel = std::max(bel,belnow);
} else {
isnot[t] = 1;
rep(i,1,l)
if(s[i] <= '9' && s[i] >= '0') nowto = nowto * 10 + s[i] - '0';
if(now > nowto || p != '%') {
flag ++;
cant[t] = 1;
}
}
}
} } else {
if(!stk.size()) {
QAQ = true;
continue;
}
//if(QAQ) continue;
if(cant[stk.top()]) flag --;
if(!isnot[stk.top()]) belnow --;
isnot[stk.top()] = 0;
cant[stk.top()] = 0;
mp[stk.top()] = 0;
if(stk.size()) stk.pop();
}
}
if(QAQ || stk.size()) {
puts("ERR");
return ;
}
if(!fs) {
puts(bel == 0 ? "Yes" : "No");
}
else puts(bel == ben ? "Yes" : "No");
}
int main() {
int T = read();
while(T --) {
mp.clear();
isnot.clear();
cant.clear();
while(stk.size()) stk.pop();
solve();
}
return 0;
}

luogu P3952 时间复杂度 模拟的更多相关文章

  1. 洛谷 - P3952 - 时间复杂度 - 模拟

    https://www.luogu.org/problemnew/show/P3952 这个模拟,注意每次进入循环的时候把新状态全部入栈,退出循环的时候就退栈. 第一次就错在发现ERR退出太及时,把剩 ...

  2. 【luogu P3952 时间复杂度】 题解

    对于2017 D1 T2 这道题 实实在在是个码力题,非常考验耐心. 其实大体的思路并不是非常难想出来,但是要注意的小细节比较多. 题目链接:https://www.luogu.org/problem ...

  3. [LUOGU] P3952 时间复杂度

    其实,也没那么难写 这种模拟题,仔细分析一下输入格式,分析可能的情况,把思路写在纸上,逐步求精,注意代码实现 主要思路就是算一个时间复杂度,和给出的复杂度比较,这就先设计一个函数把给出的复杂度由字符串 ...

  4. [NOIp2017] luogu P3952 时间复杂度

    跪着看评测很优秀. 题目描述 给你若干个程序,这些程序只有 For 循环,求这些程序的时间复杂度. Solution 大模拟.讲下细节. flag[i]flag[i]flag[i] 表示第 iii 位 ...

  5. 洛谷P3952 时间复杂度(模拟)

    题意 题目链接 Sol 咕了一年的题解..就是个模拟吧 考场上写的递归也是醉了... 感觉一年自己进步了不少啊..面向数据编程的能力提高了不少 #include<bits/stdc++.h> ...

  6. P3952 时间复杂度

    P3952 时间复杂度 题目描述 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机 ...

  7. 洛谷 P3952 时间复杂度 解题报告

    P3952 时间复杂度 题目描述 小明正在学习一种新的编程语言A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会 ...

  8. LOJ P3952 时间复杂度 noip 暴力 模拟

    https://www.luogu.org/problemnew/show/P3952 模拟,日常认识到自己zz. #include<iostream> #include<cstdi ...

  9. 洛谷P3952 时间复杂度【字符串】【模拟】

    题目描述 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会来啦!下面请你编写程序 ...

随机推荐

  1. DOS批处理:FOR中的Delims和Tokens参数

    在For命令语句的参数F中,最难理解的就是Delims和Tokens两个选项,本文简单的做一个比较和总结. “For /f”常用来解析文本,读取字符串.分工上,delims负责切分字符串,而token ...

  2. python中 yield的用法和生成器generator的说明

    详情: https://www.cnblogs.com/python-life/articles/4549996.html

  3. 状态压缩动态规划 状压DP

    总述 状态压缩动态规划,就是我们俗称的状压DP,是利用计算机二进制的性质来描述状态的一种DP方式 很多棋盘问题都运用到了状压,同时,状压也很经常和BFS及DP连用,例题里会给出介绍 有了状态,DP就比 ...

  4. Numpy系列(一)- array

    初始Numpy 一.什么是Numpy? 简单来说,Numpy 是 Python 的一个科学计算包,包含了多维数组以及多维数组的操作. Numpy 的核心是 ndarray 对象,这个对象封装了同质数据 ...

  5. openstack项目【day23】:Neutron实现网络虚拟化

    本节内容 一 Neutron概述 二 neutron openvswitch+gre/vxlan虚拟网络 三 neutron ovs opnflow流表和l2 population 四 dhcp ag ...

  6. HTML(八)HTML meta标签&base标签

    HTML meta元素 标签(meta-information)用于提供页面有关的元数据,除了提供文档字符集.使用语言.作者等基本信息外,还涉及对关键词和网页等级的设定.通过设置不同的属性,元数据可以 ...

  7. jQuery AJAX 方法 success()后台传来的4种数据

    JAVA中的四种JSON解析方式详解 jQuery AJAX 方法 success()后台传来的4种数据 1.后台返回一个页面 js代码 /**(1)用$("#content-wrapper ...

  8. EffectiveC++ 第5章 实现

    我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 5 实现 Implementations 适当提出属于 ...

  9. 异常-CDH的service无法启动并抛出异常-org.apache.avro.AvroRemoteException: java.net.ConnectException: Connection refused (Connection refused)

    1 详细异常 org.apache.avro.AvroRemoteException: java.net.ConnectException: Connection refused (Connectio ...

  10. js打印WEB页面内容代码大全

    第一种方法:指定不打印区域 使用CSS,定义一个.noprint的class,将不打印的内容放入这个class内. 详细如下: <style media=print type="tex ...