CarrotMeow @ 2023-03-11 22:43:33
好像思路没问题,但全
#include <bits/stdc++.h>
#define fo(i,a,b) for (auto i = a; i < b; i ++)
#define foe(i,a,b) for (auto i = a; i <= b; i ++)
#define of(i,b,a) for (auto i = b; i > a; i --)
#define ofe(i,b,a) for (auto i = b; i >= a; i --)
#define fi(i,s) for (auto i : s)
#define print(fmt, ...) printf(fmt, __VA_ARGS__), printf("\n")
#define sq(x) ((x) * (x))
#define cb(x) (sq(x) * (x))
#define ks(s) (string(s))
#define ts(s) (to_string(s))
#define mem(s, a) memset(s, a, sizeof(s))
#define v1 first
#define v2 second
using namespace std;
typedef long long ll;
typedef unsigned ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll inf_ll = 0x3f3f3f3f3f3f3f3fll;
template<class _Tp, const size_t __len>
using arr = _Tp [__len];
stack<int> a;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int q, n;
cin >> q;
while (q --) {
a = {};
cin >> n;
int pushed[n + 1], poped[n + 1];
foe (i, 1, n) cin >> pushed[i];
foe (i, 1, n) cin >> poped[i];
foe (i, 1, n) {
a.push(pushed[i]);
for (int j = 1; a.top() == poped[j]; j ++) {
a.pop();
if (a.empty()) break;
}
}
if (a.size()) printf("No\n");
else printf("Yes\n");
}
}
为甚么???
by ud2_ @ 2023-03-11 23:23:46
foe (i, 1, n) {
a.push(pushed[i]);
for (int j = 1; a.top() == poped[j]; j ++) {
a.pop();
if (a.empty()) break;
}
}
每次入栈后都从 1 开始重新遍历 poped 吗?
by CarrotMeow @ 2023-03-12 11:41:43
@ud2_
foe (i, 1, n) { a.push(pushed[i]); for (int j = 1; a.top() == poped[j]; j ++) { a.pop(); if (a.empty()) break; } }
每次入栈后都从
1 开始重新遍历poped
吗?
好的,我找到问题了,谢谢
已AC
by CarrotMeow @ 2023-03-12 11:42:39
======(不那么华丽的分割线)========
此贴结