社区讨论
15pts求调,悬赏2关+10rmb
P8866[NOIP2022] 喵了个喵参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhj2pkw3
- 此快照首次捕获于
- 2025/11/03 19:45 4 个月前
- 此快照最后确认于
- 2025/11/03 19:45 4 个月前
CPP
# include <bits/stdc++.h>
using namespace std;
const int N = 301;
const int M = 2e6 + 7;
int T, n, m, k;
int a[M];
int t[N][2];
int op[M << 1];
int ans[M << 1][2];
int cnt;
int to[N << 1]; int tot;
int cntk; int p[N << 1];
inline void work( int pos, int i ) { // 处理 k = 2n - 2 的情况
if(t[pos][1] == a[i]) op[++cnt] = 1, ans[cnt][0] = pos, t[pos][1] = 0;
else if(t[pos][1] > 0) {
op[++cnt] = 1, ans[cnt][0] = n;
op[++cnt] = 2, ans[cnt][0] = pos, ans[cnt][1] = n;
t[pos][0] = t[pos][1], t[pos][1] = 0;
}
else if(t[pos][0] == a[i]) op[++cnt] = 1, ans[cnt][0] = pos, t[pos][0] = 0, cntk ++;
else if(t[pos][0] > 0) op[++cnt] = 1, ans[cnt][0] = pos, t[pos][1] = a[i];
else op[++cnt] = 1, ans[cnt][0] = pos, t[pos][0] = a[i], cntk --;
}
int main() {
ios :: sync_with_stdio(false); cin.tie(0), cout.tie(0);
cin >> T;
while ( T -- ) {
// memset(t, 0, sizeof t);
cnt = 0; tot = 0;
cin >> n >> m >> k;
for ( int i = 1; i <= n; i ++) t[i][0] = t[i][1] = 0;
for ( int i = 1; i <= n; i ++) to[i] = 0;
for ( int i = 1; i <= m; i ++ ) cin >> a[i];
if ( k == n * 2 - 2 ) {
for ( int i = 1; i <= m; i ++ ) {
int pos = a[i] + 1 >> 1;
work(pos, i);
}
}
if ( k == n * 2 - 1 ) {
cntk = n;
for ( int i = 1; i <= m; i ++ ) if ( to[a[i]] == 0 ) to[a[i]] = (++ tot + 1) >> 1;
for ( int i = 1; i <= m; i ++ ) {
if ( cntk == n ) { // 我的思路是,每当序列为空的时候,找到第一个需要 k = 2n - 1 策略的点,重新分配编号。这里不太会实现呀....
memset(p, 0, sizeof p); int cntp = 0; int kk = 0, kkk = 0;
for ( int j = i; j <= m; j ++ ) {
p[a[j]] ^= 1;
if (to[a[j]] == n) kkk = a[j];
if (cntp == k) {
kk = a[j];
break;
}
cntp = p[a[j]] > 0 ? cntp + 1 : cntp - 1;
}
if(kk && kkk) swap(to[kk], to[kkk]);
cout << "kk : " << kk << " " << kkk << "\n";
}
if ( to[a[i]] != n ) work(to[a[i]], i);
if ( to[a[i]] == n ) {
if ( t[n][0] > 0 ) {
op[++cnt] = 1, ans[cnt][0] = n; t[n][0] = 0; cntk ++;
continue;
}
if ( a[i + 1] == a[i] ) {
op[++cnt] = 1, ans[cnt][0] = n;
op[++cnt] = 1, ans[cnt][0] = n;
i ++;
continue;
}
int pos = to[a[i + 1]];
if ( t[pos][1] == a[i + 1] ) {
op[++cnt] = 1, ans[cnt][0] = n; t[n][0] = a[i]; cntk --;
op[++cnt] = 1, ans[cnt][0] = pos;
t[pos][1] = 0;
i ++;
continue;
}
if ( t[pos][0] == a[i + 1] && t[pos][1] == 0 ) {
op[++cnt] = 1, ans[cnt][0] = n; t[n][0] = a[i]; cntk --;
op[++cnt] = 1, ans[cnt][0] = pos;
t[pos][0] = 0; cntk ++;
i ++;
continue;
}
if ( t[pos][0] == 0 && t[pos][1] == 0 ) {
op[++cnt] = 1, ans[cnt][0] = n; t[n][0] = a[i]; cntk --;
op[++cnt] = 1, ans[cnt][0] = pos;
t[pos][0] = a[i + 1]; cntk --;
i ++;
continue;
}
if ( t[pos][0] > 0 && t[pos][0] != a[i + 1] ) {
op[++cnt] = 1, ans[cnt][0] = n; t[n][0] = a[i]; cntk --;
op[++cnt] = 1, ans[cnt][0] = pos;
t[pos][1] = a[i + 1];
i ++;
continue;
}
if ( t[pos][0] == a[i + 1] && t[pos][1] > 0 ) {
op[++cnt] = 1, ans[cnt][0] = pos;
op[++cnt] = 1, ans[cnt][0] = n;
op[++cnt] = 2, ans[cnt][0] = pos, ans[cnt][1] = n;
t[pos][0] = t[pos][1], t[pos][1] = a[i]; cntk --;
swap(to[a[i]], to[a[i + 1]]);
i ++;
}
}
}
}
cout << cnt << "\n";
for ( int i = 1; i <= cnt; i ++ ) {
if ( op[i] == 1 ) cout << op[i] << " " << ans[i][0] << "\n";
if ( op[i] == 2 ) cout << op[i] << " " << ans[i][0] << " " << ans[i][1] << "\n";
}
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...