【題解】NOIP2017時間復雜度
阿新 • • 發佈:2018-11-09
char 大模擬 ont cal efi tchar def std err
對大模擬抱有深深的恐懼……不過這次寫好像還好?拿個棧維護一下循環的嵌套,然後重定義一下讀入即可。記得去年在考場上面死活調不粗來,代碼也奇醜無比……希望今年能好一點吧!
#include <bits/stdc++.h> using namespace std; #define maxn 100000 int L, mark[maxn]; char ans[maxn]; int fread(int t) { int x = 0, k = 1; char c; c = ans[t]; t ++;while(t < strlen(ans) && (c < ‘0‘ || c > ‘9‘)) { if(c == ‘-‘) k = -1; if(c == ‘n‘) x = 100; c = ans[t]; t ++; } while(t < strlen(ans) && c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = ans[t], t ++; returnx * k; } int read() { int x = 0, k = 1; char c; c = getchar(); while(c < ‘0‘ || c > ‘9‘) { if(c == ‘-‘) k = -1; if(c == ‘n‘) { x = 1000; return x; } c = getchar(); } while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar();return x * k; } struct node { char c; int num; node(char _c = ‘z‘ + 1, int _num = 0) { c = _c, num = _num; } }S[maxn]; void Work() { memset(mark, 0, sizeof(mark)); int cal = 0, top = 0, cnt = 0, err = 0, flag = 0; for(int i = 1; i <= L; i ++) { char c; cin >> c; if(c == ‘F‘) { char x; cin >> x; if(mark[x - ‘a‘]) flag = 1; int l = read(), r = read(); mark[x - ‘a‘] = 1; if(r - l > 100 && !err) cnt ++, cal = max(cal, cnt); if(l > r) err ++; S[++ top] = node(x, r - l); } else { if(!top) { flag = 1; continue; } mark[S[top].c - ‘a‘] = 0; if(!err) cnt -= S[top].num > 100; if(S[top].num < 0) err --; top --; } } int len = strlen(ans), tag = 0, t = 0; for(int i = 0; i < len; i ++) if(ans[i] == ‘n‘) tag = i + 2; else if(tag && i == tag) { t = fread(i); break; } if(top) flag = 1; if(flag) { printf("ERR\n"); return; } if(cal != t) flag = 1; if(flag) { printf("No\n"); return; } printf("Yes\n"); return; } int main() { int T; scanf("%d", &T); while(T --) { scanf("%d %s", &L, ans); Work(); } return 0; }
【題解】NOIP2017時間復雜度