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 时间复杂度 模拟的更多相关文章
- 洛谷 - P3952 - 时间复杂度 - 模拟
https://www.luogu.org/problemnew/show/P3952 这个模拟,注意每次进入循环的时候把新状态全部入栈,退出循环的时候就退栈. 第一次就错在发现ERR退出太及时,把剩 ...
- 【luogu P3952 时间复杂度】 题解
对于2017 D1 T2 这道题 实实在在是个码力题,非常考验耐心. 其实大体的思路并不是非常难想出来,但是要注意的小细节比较多. 题目链接:https://www.luogu.org/problem ...
- [LUOGU] P3952 时间复杂度
其实,也没那么难写 这种模拟题,仔细分析一下输入格式,分析可能的情况,把思路写在纸上,逐步求精,注意代码实现 主要思路就是算一个时间复杂度,和给出的复杂度比较,这就先设计一个函数把给出的复杂度由字符串 ...
- [NOIp2017] luogu P3952 时间复杂度
跪着看评测很优秀. 题目描述 给你若干个程序,这些程序只有 For 循环,求这些程序的时间复杂度. Solution 大模拟.讲下细节. flag[i]flag[i]flag[i] 表示第 iii 位 ...
- 洛谷P3952 时间复杂度(模拟)
题意 题目链接 Sol 咕了一年的题解..就是个模拟吧 考场上写的递归也是醉了... 感觉一年自己进步了不少啊..面向数据编程的能力提高了不少 #include<bits/stdc++.h> ...
- P3952 时间复杂度
P3952 时间复杂度 题目描述 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机 ...
- 洛谷 P3952 时间复杂度 解题报告
P3952 时间复杂度 题目描述 小明正在学习一种新的编程语言A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会 ...
- LOJ P3952 时间复杂度 noip 暴力 模拟
https://www.luogu.org/problemnew/show/P3952 模拟,日常认识到自己zz. #include<iostream> #include<cstdi ...
- 洛谷P3952 时间复杂度【字符串】【模拟】
题目描述 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会来啦!下面请你编写程序 ...
随机推荐
- <锋利的jQuery>读书笔记
- strace -> System call tracer
我只想告诉你一件事: strace 可以让你知道程序调用了哪些syscall.
- Coroutine的原理以及实现
最近在写WinForm,在UI界面需要用到异步的操作,比如加载数据的同时刷系进度条,WinForm提供了不少多线程的操作, 但是多线程里,无法直接修改主线程里添加的UI的get/set属性访问器(可以 ...
- iTOP-iMX6开发板-Android-can测试例程介绍
TOP-iMX6开发板的 Android 源码的 can 例程包含在 Android 源码中,在“ packages/apps/”目 录下,如下图所示,这个是应用界面的源码. 如下图所示,can ...
- String总结
- 在GridView中使用FindControl
DataRowView dv =(DataRowView)e.Row.DataItem;string id=dv.Row["ProjectID"].ToString(); 1.在行 ...
- linux 下nginx 集群CAS单点登录实现
1.单点登录服务器CAS应用配置于tomcat下. 1)key生成: keytool -genkey -alias mycas -keyalg RSA -keysize 2048 -keystore ...
- 华为mate10 UA
Dalvik/2.1.0 (Linux; U; Android 9; ALP-AL00 Build/HUAWEIALP-AL00) "user-agent": "Mozi ...
- typecho视频播放插件JWPlayer
JWplayer for typecho是羽中大神开发并持续维护的一款插件,目前插件已经发布了8个版本,涵盖typecho0.8到1.0,插件基于原生的JWPlayer,可以说非常完美,详细使用方法在 ...
- switch case 遇到判断type分支的写法
一叶障目,没有接触到的知识点真是太多了...... 最近项目里需要用到一个小工具,就用winform写了一个出来,然后需要一个功能就是清空控件内容,我这个工具就用到了textbox和combobox, ...