大毒瘤......

时隔快半年我终于花了两个小时堪堪A掉这一题...果然我还没有准备好。

想法:用DFS模拟递归。

时间复杂度的处理:每层循环取max,然后相加。

最大难点:各种繁杂而令人发指的特判。

为了简明代码,我写了6个辅助函数。

然后就A了...

 // shi jian fu za du
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream> const int ERR = -; int L, vis[]; inline int getOP() { /// F 0 E 1
L--;
char c = getchar();
while(c != 'E' && c != 'F') {
c = getchar();
}
return c == 'E';
}
inline int getName() {
char c = getchar();
while(c < 'a' || c > 'z') {
c = getchar();
}
return c - 'a';
}
inline int getSum() {
int Sum = ;
char c = getchar();
while(c != 'n' && (c < '' || c > '')) {
c = getchar();
}
if(c == 'n') {
return -;
}
while(c >= '' && c <= '') {
Sum = (Sum << ) + (Sum << ) + c - ;
c = getchar();
}
return Sum;
}
inline void getrest() {
while(L) {
int t = getOP();
if(!t) {
t = getName();
t = getSum();
t = getSum();
}
}
return;
}
inline int get(std::string s) {
if(s[] == '') {
return ;
}
int ans = ;
for(int i = ; i < s.size() - ; i++) {
ans = (ans << ) + (ans << ) + s[i] - ;
}
return ans;
}
inline int gettime(int a, int b) {
if(a == - && b == -) {
return ;
}
else if(a == -) {
return -;
}
else if(b == -) {
return ;
}
else if(a <= b) {
return ;
}
return -;
}
//
inline int DFS(int k, int time) {
int ans = , nex_time;
while(L) {
int t = getOP();
if(t == ) {
if(!k) {
getrest();
return ERR;
}
break;
}
/// F
int name = getName();
int a = getSum();
int b = getSum();
if(vis[name]) {
getrest();
return ERR;
}
if(!L) {
return ERR;
}
vis[name] = ;
nex_time = gettime(a, b); t = DFS(k + , nex_time);
vis[name] = ;
if(t == ERR) {
return ERR;
}
if(!L && k) {
return ERR;
}
ans = std::max(ans, t);
}
if(time == -) {
return ;
}
return time + ans;
} int main() {
int T;
scanf("%d", &T);
std::string s;
while(T--) {
scanf("%d", &L);
std::cin >> s;
int t = get(s);
int g = DFS(, );
if(g == ERR) {
printf("ERR\n");
}
else if(g == t) {
printf("Yes\n");
}
else {
printf("No\n");
}
}
return ;
}

AC代码

[update 2018.10.11]

额,最近练模拟,想起来这道题。因为以前做过一次所以很轻易就A了。

大概十几分钟打完(记得之前是怎么处理的),第一次交80分,还是个老问题:没有把之前剩余的语句读完。

还需要注意对第一次操作的处理:结束时你没有一个多余的E让你出来,你要自己特判L = 0,然后如果不在最外层的话就是error。

 #include <cstdio>
#include <map>
#include <cstring> std::map<char, bool> mp;
char s[];
int L, err; inline int read_time() {
scanf("%s", s);
if(s[] == '') {
return ;
}
int x = ;
for(int i = ; i < strlen(s) - ; i++) {
x = (x << ) + (x << ) + s[i] - ;
}
return x;
} inline int read_op() {
L--;
scanf("%s", s);
return s[] == 'E';
} inline int read(char &c) {
scanf("%s", s);
c = s[];
scanf("%s", s);
int a = , b = ;
if(s[] == 'n') {
a = ;
}
else {
for(int i = ; i < strlen(s); i++) {
a = (a << ) + (a << ) + s[i] - ;
}
}
scanf("%s", s);
if(s[] == 'n') {
b = ;
}
else {
for(int i = ; i < strlen(s); i++) {
b = (b << ) + (b << ) + s[i] - ;
}
}
if(a == ) {
if(b == ) {
return ;
}
else {
return -;
}
}
if(b == ) {
return ;
}
if(a > b) {
return -;
}
return ;
} int solve(int k, char c) {
int large = ;
char j;
while() {
if(!L) {
if(c != '') {
err = ;
}
break;
}
int f = read_op();
if(f) {
break;
}
int temp = read(j);
if(mp[j]) {
err = ;
}
mp[j] = ;
large = std::max(large, solve(temp, j));
}
mp[c] = ;
if(k == -) {
return ;
}
return large + k;
} inline void work() {
scanf("%d", &L);
err = ;
mp.clear();
int time = read_time();
int ans = solve(, '');
if(L) {
err = ;
while(L) {
if(!read_op()) {
read(s[]);
}
}
}
if(err) {
printf("ERR\n");
return;
}
if(ans == time) {
printf("Yes\n");
}
else {
printf("No\n");
}
return;
} int main() {
int T;
scanf("%d", &T);
while(T--) {
work();
}
return ;
}

AC代码

洛谷P3952 时间复杂度的更多相关文章

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

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

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

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

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

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

  4. 计蒜客 时间复杂度 (模拟) & 洛谷 P3952 时间复杂度

    链接 : Here! 思路 : 这是一道大模拟, 区分好情况就没问题了 循环构成部分 : $F , x , i , j$ 和 $E$ , 需要注意的是 $i , j$, - 分析 $i, j$ 的情况 ...

  5. 洛谷 P3952时间复杂度 (本地AC测评RE的伪题解)

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

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

    传送门 惊叹考场dubuffdubuffdubuff. 这题还没有梭哈难啊233. 直接按照题意模拟就行了. 代码: #include<bits/stdc++.h> using names ...

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

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

  8. 洛谷 P3952 时间复杂度【模拟】

    把No写成NO,WA了一发-- 现在看这题也不难-- 用一个栈,记一下前面F的字母,是否合法,合法的有多长,每次入栈弹栈即可 #include<iostream> #include< ...

  9. 【题解】洛谷P3952 [NOIP2017TG] 时间复杂度(模拟)

    题目来源:洛谷P3952 思路 纯模拟没啥可说的了 果然好复杂 参考了你谷一个40行代码 代码 #include<iostream> #include<cstdio> #inc ...

随机推荐

  1. 浅谈nornalize.css(含源码)

    Normalize.css是一种CSS reset的替代方案.经过@necolas和@jon_neal花了几百个小时来努力研究不同浏览器的默认样式的差异,这个项目终于变成了现在这样. 我们创造norm ...

  2. Html5前端笔记

    获取Dpi 在 window.load中添加: (function(){ if (!window.screen.deviceXDPI){ var tmpNode = document.createEl ...

  3. Linux下IP SAN共享存储操作记录

    一.简单介绍SAN,即存储区域网络(storage area network and SAN protocols),它是一种高速网络实现计算机与存储系统之间的数据传输.常见的分类是FC-SAN和IP- ...

  4. python-深浅copy-18

    # 赋值运算l1 = [1,2,3]l2 = l1l1.append('a')print(l1,l2) # [1, 2, 3, 'a'] [1, 2, 3, 'a'] #copyl1 = [1,2,3 ...

  5. Promise 原理

    异步:可同时好几件事,互不影响: 同步:按循序一件一件.... 异步好多缺点:.... promise就是解决异步计算的这些缺点的,主要用于: 1.异步计算: 2.可以将异步操作队列化  按期望的顺序 ...

  6. Daily Scrum- 12/23

    Meeting Minutes 与Travis和Zhongqiu讨论了Beta的Feature以及更长期的计划: 讨论了一些使用及设计上的Bug (Feature); 开始了新的开发周期: Burnd ...

  7. Doors Breaking and Repairing CodeForces - 1102C (思维)

    You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consi ...

  8. HTML DOM 学习笔记

    一.HTML DOM定义了所有HTML元素的对象和属性,以及访问他们的方法即:HTML DOM是关于如何获取,修改,添加,删除HTML元素的标准二.DOM节点1.分类整个文档是一个文档节点每个HTML ...

  9. PHP微信支付案例收录

    微信支付API 文档:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1&index=1# TP 微信 + 支 ...

  10. [小知识] 关闭我的电脑里面的百度网盘以及修改win+e快捷键打开我的电脑

    1. 登录百度云盘客户端 设置->基本->取消在我的电脑中显示百度网盘 2. 修改win+e的默认显示 打开我的电脑. 选择查看-选项 文件夹选项修改为: 此电脑即可..