luogu P3952 时间复杂度 模拟

题目链接

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;
}
上一篇:史上最全面的SignalR系列教程-3、SignalR 实现推送功能-集线器类实现方式


下一篇:XMind 是一个全功能的思维导图和头脑风暴软件,为激发灵感和创意而生