洛谷P3952 时间复杂度(模拟)
题意
Sol
咕了一年的题解。。就是个模拟吧
考场上写的递归也是醉了。。。
感觉一年自己进步了不少啊。。面向数据编程的能力提高了不少
#include<bits/stdc++.h>
#define fi first
#define se second
#define MP make_pair
using namespace std;
const int MAXN = 101;
int T, top = 0, now, mx, flag;
pair<char, int> st[MAXN];// first 字符 second 是否算作复杂度 1 算 0不算
void init() {
top = 0;//已经用过哪些字符
now = 0;//当前进入了几层循环
mx = 0;//最大循环层数
flag = 0;
}
int get(char *s) {
int l = strlen(s + 1), x = 0;
for(int i = 1; i <= l; i++) if(s[i] >= '0' && s[i] <= '9') x = x * 10 + s[i] - '0';
return x;
}
char getopt() {
char c = ' ';
while(c != 'E' && c != 'F') c = getchar();
return c == 'F' ? 1 : 0;// 1 enter 0 end
}
int readround() {//n = -1
char c = ' '; int x = 0;
while(c != 'n' && (c < '0' || c > '9')) c = getchar();
if(c == 'n') return -1;
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}
int readbuf() {// 1 n 0常数 -1重名
char c = getchar();
while(c < 'a' || c > 'z') c = getchar();
int bg = readround(), ed = readround();
for(int i = 1; i <= top; i++) if(st[i].fi == c) return -1;
if((bg != -1 && ed != -1 && bg > ed) || (bg == -1 && ed != -1)) {flag = 1, st[++top] = MP(' ', -1); return 0;}//不进入循环
if(bg != -1 && ed == -1) {//非常数循环
if(flag == 0) now++, mx = max(now, mx), st[++top] = MP(c, 1);
else st[++top] = MP(c, 0);
} else {
st[++top] = MP(c, 0);
}
return 0;
}
int solve() {// 1 Yes 0 No -1 ERR
int L, w = 0, GG = 0; char s[233];
scanf("%d %s", &L, s + 1);
if(s[3] == 'n') w = get(s + 1);
for(int i = 1; i <= L; i++) {
int opt = getopt();
if(opt == 0) {
if(top == 0) GG = -1;
else {
if(st[top].se == -1) flag = 0;
if(st[top--].se == 1) now--;
}
} else {
int tmp = readbuf();
if(tmp == -1) GG = -1;
}
}
if(GG == -1) return -1;
if(top) return -1;
else return mx == w;
}
int main() {
cin >> T;
while(T--) {
init();
int tmp = solve();
if(tmp == 1) puts("Yes");
else if(tmp == 0) puts("No");
else puts("ERR");
}
return 0;
}
/*
1
2 O(n^1)
F a n n
E
*/
洛谷P3952 时间复杂度(模拟)的更多相关文章
- 洛谷 - P3952 - 时间复杂度 - 模拟
https://www.luogu.org/problemnew/show/P3952 这个模拟,注意每次进入循环的时候把新状态全部入栈,退出循环的时候就退栈. 第一次就错在发现ERR退出太及时,把剩 ...
- 洛谷 P3952 时间复杂度 解题报告
P3952 时间复杂度 题目描述 小明正在学习一种新的编程语言A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会 ...
- 洛谷P3952 时间复杂度【字符串】【模拟】
题目描述 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会来啦!下面请你编写程序 ...
- 计蒜客 时间复杂度 (模拟) & 洛谷 P3952 时间复杂度
链接 : Here! 思路 : 这是一道大模拟, 区分好情况就没问题了 循环构成部分 : $F , x , i , j$ 和 $E$ , 需要注意的是 $i , j$, - 分析 $i, j$ 的情况 ...
- 2018.11.02 洛谷P3952 时间复杂度(模拟)
传送门 惊叹考场dubuffdubuffdubuff. 这题还没有梭哈难啊233. 直接按照题意模拟就行了. 代码: #include<bits/stdc++.h> using names ...
- 洛谷 P3952 时间复杂度【模拟】
把No写成NO,WA了一发-- 现在看这题也不难-- 用一个栈,记一下前面F的字母,是否合法,合法的有多长,每次入栈弹栈即可 #include<iostream> #include< ...
- 洛谷P3952 时间复杂度
大毒瘤...... 时隔快半年我终于花了两个小时堪堪A掉这一题...果然我还没有准备好. 想法:用DFS模拟递归. 时间复杂度的处理:每层循环取max,然后相加. 最大难点:各种繁杂而令人发指的特判. ...
- 洛谷 P3952时间复杂度 (本地AC测评RE的伪题解)
[题目描述] 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会来啦!下面请你编写 ...
- 【题解】洛谷P3952 [NOIP2017TG] 时间复杂度(模拟)
题目来源:洛谷P3952 思路 纯模拟没啥可说的了 果然好复杂 参考了你谷一个40行代码 代码 #include<iostream> #include<cstdio> #inc ...
随机推荐
- kafka-0.9
1)yum install java 2)curl -L -O http://mirrors.cnnic.cn/apache/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz ...
- 无法下载APP
最近遇见下面的情况两次,各种搜索过资料,但是都没什么结果,把自己的解决方法分享如下: 实践证明,出现这个问题,应该是出现了下面几方面原因: 第一次遇见上述问题,是年后来到公司接手了新项目,然后不久传来 ...
- 2018年10月19 手记 - 身为开发者的我de窘境
从10月1国庆过完节回来,那已经是7号了,之后便开始紧锣密鼓的筹划着接下来11月份的公司组织的对外活动,这边新来的产品对产品或者说对任务很是负责,并且策划了很多的方案,并且乐意站在我们开发的角度上去考 ...
- tomcat正常启动后http://localhost:8080/报错404
病症: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问.关闭eclipse里面的tomca ...
- maven 打包 源代码
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-sourc ...
- centos崩溃后如何修复
首先看能不能进单用户模式,能进去,就用mount -o remount,rw / 重置成可写的. 不能进单用户模式,就进入光盘救援模式,进去挂载了系统,这时候通常是必要的动态静态库出了问题,先应该做的 ...
- WorldCount 结对项目
合作者:201631062501,201631062129 代码地址:https://gitee.com/guilinyunya/WorldCount 伙伴博客地址:https://www.cnblo ...
- tess4j 注意事项
依赖: <dependency> <groupId>net.sourceforge.tess4j</groupId> <artifactId>tess4 ...
- Vue axios 上传图片
上传图片接口 // 上传图片 export const uploadBanner = formData => { return axios.request({ url: 'manage/slid ...
- Mac系统下Eclipse代码联想功能(代码助手,代码提示)快捷键
Eclipse for mac 代码提示(代码助手,代码联想)快捷键修改一.每次输入都自动提示点击Eclipse,使其成为第一响应者,preferences->Java->Editor-& ...