大毒瘤......

时隔快半年我终于花了两个小时堪堪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. Canary机制的绕过

    目标程序下载 提取码:8ypi 1.检查程序开启了哪些安全保护机制 Canary与NX开启了 Canary机制简介 64位的canary机制,会在函数头部添加: mov rax,QWORD PTR f ...

  2. ruby安装及升级

    在centos6.x下执行上面的"gem install redis"操作可能会报错,坑很多!默认yum安装的ruby版本是1.8.7,版本太低,需要升级到ruby2.2以上,否则 ...

  3. Redis+Keepalived高可用环境部署记录

    Keepalived 实现VRRP(虚拟路由冗余)协议,从路由级别实现VIP切换,可以完全避免类似heartbeat脑裂问题,可以很好的实现主从.主备.互备方案,尤其是无状态业务,有状态业务就需要额外 ...

  4. Linux下FastDFS分布式存储-总结及部署记录

    一.分布式文件系统介绍分布式文件系统:Distributed file system, DFS,又叫做网络文件系统:Network File System.一种允许文件通过网络在多台主机上分享的文件系 ...

  5. Gerrit日常维护记录

    Gerrit代码审核工具是个好东西,尤其是在和Gitlab和Jenkins对接后,在代码控制方面有着无与伦比的优势. 在公司线上部署了一套Gerrit系统,在日常运维中,使用了很多gerrit命令,在 ...

  6. Spring方法级别的验证

    设置验证点及验证方式(1)Spring方法级别的验证有多种验证方式,比较常用的有 @NotBlank:主要是对字符串的验证,不为null且去除空白符之后长度大于0 @NotNull:主要是对对象的验证 ...

  7. 《Linux内核设计与实现》第四章学习笔记

    <Linux内核设计与实现>第四章学习笔记           ——进程调度 姓名:王玮怡  学号:20135116 一.多任务 1.多任务操作系统的含义 多任务操作系统就是能同时并发地交 ...

  8. Linux课题实践五——字符集总结与分析

    Linux课题实践三——字符集总结与分析 20135318  刘浩晨 字符是各种文字和符号的总称,包括各国家文字.标点符号.图形符号.数字等.字符集是多个字符的集合,字符集种类较多,每个字符集包含的字 ...

  9. Linux内核第六节 20135332武西垚

    如何描述一个进程:进程描述符的数据结构: 如何创建一个进程:内核是如何执行的,以及新创建的进程从哪里开始执行: 使用gdb跟踪新进程的创建过程. 进程的描述 操作系统三大功能: 进程管理(最核心最基础 ...

  10. React16新特性

    React的16版本采用了MIT开源许可证,新增了一些特性. Error Boundary render方法新增返回类型 Portals 支持自定义DOM属性 setState传入null时不会再触发 ...