题目链接

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 时间复杂度 模拟的更多相关文章

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

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

  2. 【luogu P3952 时间复杂度】 题解

    对于2017 D1 T2 这道题 实实在在是个码力题,非常考验耐心. 其实大体的思路并不是非常难想出来,但是要注意的小细节比较多. 题目链接:https://www.luogu.org/problem ...

  3. [LUOGU] P3952 时间复杂度

    其实,也没那么难写 这种模拟题,仔细分析一下输入格式,分析可能的情况,把思路写在纸上,逐步求精,注意代码实现 主要思路就是算一个时间复杂度,和给出的复杂度比较,这就先设计一个函数把给出的复杂度由字符串 ...

  4. [NOIp2017] luogu P3952 时间复杂度

    跪着看评测很优秀. 题目描述 给你若干个程序,这些程序只有 For 循环,求这些程序的时间复杂度. Solution 大模拟.讲下细节. flag[i]flag[i]flag[i] 表示第 iii 位 ...

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

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

  6. P3952 时间复杂度

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

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

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

  8. LOJ P3952 时间复杂度 noip 暴力 模拟

    https://www.luogu.org/problemnew/show/P3952 模拟,日常认识到自己zz. #include<iostream> #include<cstdi ...

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

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

随机推荐

  1. MySQL 导出数据库,出现 “mysqldump: Got error: 1146”

    出现场景 在 cmd 导出数据库时: mysqldump -hlocalhost -uroot -p student_db > C:\student_db.sql 出现: mysqldump: ...

  2. Gym - 101350A Sherlock Bones(思维)

    The great dog detective Sherlock Bones is on the verge of a new discovery. But for this problem, he ...

  3. building tool的简单了解

    java常用的三种构建工具: Apache Maven ——主要用于构建Java项目的自动化工具. NetBeans IDE 支持 Maven 构建系统,可帮助您管理项目的依赖关系.构建.报告和文档. ...

  4. 【.net】未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序解决办法

    #错误描述: 在开发.net项目中,通过microsoft.ACE.oledb读取excel文件信息时,报错: “未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序” # ...

  5. 第十五节: EF的CodeFirst模式通过DataAnnotations修改默认协定

    一. 简介 1. DataAnnotations说明:EF提供以特性的方式添加到 domain classes上,其中包括两类:  A:System.ComponentModel.DataAnnota ...

  6. Beamer 跳到另外一页

    \documentclass[english]{beamer}\usepackage{babel} \begin{document} \begin{frame}\frametitle{the refe ...

  7. Geometric regularity criterion for NSE: the cross product of velocity and vorticity 1: $u\times \om$

    在 [Chae, Dongho. On the regularity conditions of suitable weak solutions of the 3D Navier-Stokes equ ...

  8. [物理学与PDEs]第5章习题6 各向同性材料时强椭圆性条件的等价条件

    在线性弹性时, 证明各向同性材料, 强椭圆性条件 (5. 6) 等价于 Lam\'e 常数满足 $$\bex \mu>0,\quad \lm+2\mu>0.  \eex$$ 证明: (1) ...

  9. 练习:javascript淡入淡出半透明效果

    划过无透明 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  10. Leetcode#191. Number of 1 Bits(位1的个数)

    题目描述 编写一个函数,输入是一个无符号整数,返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量). 示例 : 输入: 11 输出: 3 解释: 整数 11 的二进制表示为 000000 ...