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++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会来啦!下面请你编写程序 ...
随机推荐
- OSU! on tree
dsu on tree 好吧,这个毒瘤...... 树剖和启发式合并的杂合体. 用于解决静态子树问题,复杂度O(nlogn * insert时间) 因为dsu是并查集的意思所以算法名字大概就是什么树上 ...
- 数据库导出excel,前后端分离
主要参考了这篇博文:https://www.cnblogs.com/jerehedu/p/4343509.html 2.3和2.4 采用xssf,依赖:compile group: 'org.apa ...
- 金融量化分析【day111】:Matplotib-图标标注
一.图像标注 1.股票 df = pd.read_csv('601318.csv') df.plot() plt.plot([1,3,4,5]) plt.plot([5,8,7,9]) plt.tit ...
- MongoDB and GUI 管理界面
MongoDB https://www.mongodb.com/ MongoDB AtlasDatabase as a Service The best way to deploy, operate, ...
- [译]Ocelot - Middleware Injection and Overrides
原文 使用这个特性的时候要小心点. 可以如下一样提供一些中间件用以覆盖默认的中间件: var configuration = new OcelotPipelineConfiguration { Pre ...
- Codeforces 1088F(贪心+倍增)
题目链接 题意 构造一颗树使得满足计算方法的结果最小. 思路 考虑两棵树,一棵为题目中的询问构成的树$T1$,一棵为要构造的满足最终答案的树$T2$.从$T1$点权最小的点向外构造$T2$,在$T1$ ...
- rest_framework框架的认识
它是基于Django的,帮助我们快速开发符合RESTful规范的接口框架. 一 路由 可以通过路由as_view()传参 根据请求方式的不同执行对应不同的方法 在routers模块下 封装了很多关于 ...
- 萌新的IDEA_web开发笔记(未完)
萌新IDEA_web开发笔记 按兴趣自己搞的网页: http://47.94.140.98:8080/ow_web/my_web/web/ 暂时还没做完. 部署在租的服务器上面,背景视频加载可能有点慢 ...
- windows配置openssl
下载openssl并安装,下载地址:http://slproweb.com/products/Win32OpenSSL.html 假设安装路径为C:\"Program Files" ...
- mysql 备份报错mysqldump: [Warning] Using a password on the command line interface can be insecure.
-------------------------------------------------------------------------------- mysql 备份报错mysqldump ...