原題傳送門
寫的我一口老血
你得先想好
什麼時候會
- 變量名衝突(那麼需要的是一個變量名的桶)
- E多了或F多了(需要一個記錄目前存在幾重循環的變量)
然後你得知道當前的循環到底有沒有用
具體來說是這個循環的外面是否有類似
的情況
那麼需要一個記錄外面依然有幾個這樣的循環的變量
接着你要明確當前是否嵌套以及已經嵌套了幾層
那麼我又要處理的大小關係,以及一個記錄嵌套層數的變量,記錄答案
最後你的時候根據當前是否在無用循環裏面(還不爲0)或者當前結束的循環到底有沒有嵌套出一個n來決定是否--cyclenum;--cannot
梳理了一下感覺這個模擬題目就十分清晰有沒有
但是還是千萬記住一點,別再中途,否則你讀不完
Code:
#include <bits/stdc++.h>
#define maxn 10010
using namespace std;
char s[maxn];
struct node{
char x;
int time;
}a[maxn];
int used[maxn], n;
int main(){
int T;
scanf("%d", &T);
while (T--){
int goal = 0, cyclenum = 0, iferror = 0, cannot = 0, maxtime = 0, tot = 0;
memset(used, 0, sizeof(used));
scanf("%d", &n), scanf("%s", s + 1);
if (s[3] == 'n')
for (int i = 5; i <= strlen(s + 1) - 1; ++i) goal = (goal << 1) + (goal << 3) + (s[i] ^ 48);
while (n--){
scanf("%s", s + 1);
if (s[1] == 'E'){
if (!tot) iferror = 1;
used[a[tot].x] = 0;
if (!a[tot].time) --cannot; else
if (!cannot && a[tot].time == 2) --cyclenum;
--tot;
} else{
scanf("%s", s + 1);
char x = s[1];
if (used[x]) iferror = 1;
used[x] = 1;
scanf("%s", s + 1);
int pos = 1, l = 0, r = 0, time;
if (s[pos] == 'n') l = 1e4; else while (pos <= strlen(s + 1)) l = (l << 1) + (l << 3) + (s[pos++] ^ 48);
scanf("%s", s + 1);
pos = 1;
if (s[pos] == 'n') r = 1e4; else while (pos <= strlen(s + 1)) r = (r << 1) + (r << 3) + (s[pos++] ^ 48);
if (r < l) time = 0; else
if (r - l > 1e3) time = 2; else time = 1;
if (!time) ++cannot; else
if (time == 2 && !cannot) maxtime = max(maxtime, ++cyclenum);
a[++tot] = (node){x, time};
}
}
if (tot || iferror) puts("ERR"); else
if (maxtime == goal) puts("Yes"); else puts("No");
}
return 0;
}