[Luogu] 时间复杂度
https://www.luogu.org/problemnew/show/P3952
考场上输出的是 "YES" "NO"
++ ,如果不是亲身经历,打死我我都不信
思路:
递归模拟
细节挺多
难度不大
容易写挂
#include <bits/stdc++.h> using namespace std;
const int oo = ; int T, L, Maxpow;
char use[];
bool vis[], flag;
int last; inline int get() {
char c[];
scanf("%s", c);
int len = strlen(c);
int ret = ;
if(len == ) return c[] == 'n' ? oo : c[] - '';
else for(int i = ; i < len; i ++) ret = ret * + c[i] - '';
return ret;
} void Go_on() {
int jsF(), jsE();
while(jsE <= jsF) {
L --;
char H; cin >> H;
if(H == 'E') {jsE ++; vis[use[last --]] = ; if(jsE > jsF) return ;}
else {
char Int; int x, y;
cin >> Int; x = get(); y = get();
if(vis[Int]) {flag = ; return ;}
else {vis[Int] = ; use[++ last] = Int;}
jsF ++;
}
}
} void Work(int floor_pow, int floor) { // 到达当前层时的最大次数
while(L) {
if(flag) return ;
L --;
char H; cin >> H;
if(H == 'F') {
char Int; cin >> Int; int x = get(), y = get();
if(vis[Int]) {flag = ; return ;}
else {vis[Int] = ; use[++ last] = Int;}
if(x != oo && y == oo) {
Maxpow = max(Maxpow, floor_pow + );
Work(floor_pow + , floor + );
} else {
if((x == oo && y != oo) || (x > y)) {Go_on();}
else Work(floor_pow, floor + );
}
} else {
vis[use[last --]] = ;
if(floor != ) return ;
}
} } inline void Read_over() {
while(L) {L --; char H; cin >> H; if(H == 'F') {cin >> H; H = get(); H = get();}}
} int main() {
cin >> T;
while(T --) {
cin >> L;
char tim[];
scanf("%s", tim);
memset(vis, , sizeof vis); last = ;
int len = strlen(tim);
if(L % ) {cout << "ERR" << endl; Read_over(); continue ;}
Maxpow = ; last = ; flag = ;
Work(, );
if(L) Read_over();
if(last || flag) {cout << "ERR" << endl; continue ;}
int Pow;
if(tim[] == '') Pow = ;
else if(len == ) Pow = tim[] - '';
else if(len == ) Pow = (tim[] - '') * + tim[] - '';
else if(len == ) Pow = ((tim[] - '') * + tim[] - '') * + tim[] - '';
if(Pow == Maxpow) cout << "Yes" << endl;
else cout << "No" << endl;
}
return ;
}
[Luogu] 时间复杂度的更多相关文章
- luogu P3952 时间复杂度 模拟
题目链接 luogu P3952 时间复杂度 题解 直接模拟即可 注意不要直接return 我真是naive ...... 代码 #include<map> #include<sta ...
- [Luogu 3952] NOIP2017 时间复杂度
[Luogu 3952] NOIP2017 时间复杂度 一年的时间说长不长,说短,也不短. 一年之内无数次觉得难得可怕的题目,原来也就模拟这么回事儿. #include <cstdio> ...
- 【luogu P3952 时间复杂度】 题解
对于2017 D1 T2 这道题 实实在在是个码力题,非常考验耐心. 其实大体的思路并不是非常难想出来,但是要注意的小细节比较多. 题目链接:https://www.luogu.org/problem ...
- [LUOGU] P3952 时间复杂度
其实,也没那么难写 这种模拟题,仔细分析一下输入格式,分析可能的情况,把思路写在纸上,逐步求精,注意代码实现 主要思路就是算一个时间复杂度,和给出的复杂度比较,这就先设计一个函数把给出的复杂度由字符串 ...
- luogu 3952 时间复杂度
noip2017 D1T2 时间复杂度 某zz选手考场上写了1.5h 考完之后发现自己写的是错的 但是结果A了??? 题目大意: 一种新的编程语言 A++ 给出一个程序只有循环语句 并给出这个程序的时 ...
- luogu 3952 时间复杂度(模拟)
时间复杂度 这道题从两个月前开始做,一直没做出来,最后今晚决心一定要做出来.于是开始认真的在打草纸上写思路,最后在AC的那一刻,差点哭了出来!! 题目大意 这个自己看吧,noip2017的D1T2 s ...
- [NOIp2017] luogu P3952 时间复杂度
跪着看评测很优秀. 题目描述 给你若干个程序,这些程序只有 For 循环,求这些程序的时间复杂度. Solution 大模拟.讲下细节. flag[i]flag[i]flag[i] 表示第 iii 位 ...
- luogu P4183 Cow at Large P (暴力吊打点分治)(内有时间复杂度证明)
题面 贝茜被农民们逼进了一个偏僻的农场.农场可视为一棵有N个结点的树,结点分别编号为 1,2,-,N .每个叶子结点都是出入口.开始时,每个出入口都可以放一个农民(也可以不放).每个时刻,贝茜和农民都 ...
- [luogu P2647] 最大收益(贪心+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...
随机推荐
- LC 387. First Unique Character in a String
题目描述 Given a string, find the first non-repeating character in it and return it's index. If it doesn ...
- iframe/frameset/frame的区别
目录 iframe iframe属性的用法 iframe属性的取值 iframe的书写格式 frameset frameset的用法(框架模板) frameset属性的属性值 frame frame的 ...
- 【转】iis7下站点日志默认位置
本文转自:http://www.cnblogs.com/mincyw/p/3425468.html 在iis6时,通过iis管理器的日志配置可以找到站点日志存储的位置. 但是在iis7下,iis管理器 ...
- Flask 卡住, 无响应问题
自己学习Flask+Gevent, 做了一个小接口服务器, 但在收到请求后, 打印请求的报文, 并返回正确格式, 运行后会出现收到请求消息后,Flask卡住无响应的的问题, 有时候点击ctrl+C才能 ...
- 3037 插板法+lucas
先说下lucas定理 1)Lucas定理:p为素数,则有: (2)证明: n=(ak...a2,a1,a0)p = (ak...a2,a1)p*p + a0 = [n/p]*p+a0 (注意 这里( ...
- C++ STL 之 multimap案例之员工分组
#include <iostream> #include <vector> #include <map> #include <string> #incl ...
- 安卓开发之sql语句增删改查2(利用谷歌封装好的API进行增删改查)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 安卓开发之ListView入门
<!--这个地方最好用match_parent 这样效率高--> <ListView android:layout_width="match_parent" an ...
- 不怕你配置不会,就怕你看的资料不对!MIM 与 SharePoint 同步完全配置指南。
为了更好的同步 User Profile,在 SharePoint 2010 中首次引入了 FIM (ForeFront Identity Manager) 用于编辑 User Profile 的同期 ...
- android程序复制数据库
一般项目中我们把db文件放到assert或者raw目录下面,在程序第一次启动的时候复制到私有目录下面 在使用过程中,老是发现复制不成功,私有目录下的db文件总是3072 后来发现应该是使用Conten ...