社区讨论
模拟检测机
P8866[NOIP2022] 喵了个喵参与者 3已保存回复 9
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 9 条
- 当前快照
- 1 份
- 快照标识符
- @mhj2qz9e
- 此快照首次捕获于
- 2025/11/03 19:46 4 个月前
- 此快照最后确认于
- 2025/11/03 19:46 4 个月前
CPP
1 // 只能为 1 ,不输入这个 T
2 4 2
1 2 1 2
CPP5
1 1
1 1
1 2
2 1 2
1 1
检测机样例:
CPP2 4 2
1 2 1 2
5
1 1
1 1
1 2
2 1 2
1 1
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1050;
const int M = 3; // 每个栈的容量(能存多少个数)
int n, m, k, a[N];
int len, x[N], y[N], z[N];
int cnt[N], stk[N][N];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
scanf("%d", &len);
for (int i = 1; i <= len; i++) {
scanf("%d%d", &x[i], &y[i]);
if (x[i] == 2) scanf("%d", &z[i]);
}
int u = 1, v = 1;
while (1) {
system("cls");
puts("Sample:");
for (int i = M; i >= 1; i--) {
for (int i = 1; i <= n; i++) printf("+---");
puts("+");
for (int j = 1; j <= n; j++) {
if (stk[j][i]) printf("|%3d", stk[j][i]);
else printf("| ");
}
puts("|");
}
for (int i = 1; i <= n; i++) printf("+---");
puts("+");
system("pause");
if (x[u - 1] == 1 && cnt[y[u - 1]] >= 2 && stk[y[u - 1]][cnt[y[u - 1]]] == stk[y[u - 1]][cnt[y[u - 1]] - 1]) {
stk[y[u - 1]][cnt[y[u - 1]]] = stk[y[u - 1]][cnt[y[u - 1]] - 1] = 0;
cnt[y[u - 1]] -= 2;
} else {
if (u == len + 1) break;
if (x[u] == 1) {
stk[y[u]][++cnt[y[u]]] = a[v++];
u++;
if (cnt[y[u]] == M + 1) {
printf("The capacity of Stack %d exceeds %d !\n\n", y[u], M);
return 0;
}
} else {
if (stk[y[u]][1] != stk[z[u]][1]) {
printf("The bottom element of stack %d is different from the bottom element of stack %d !\n\n", y[u], z[u]);
return 0;
} else if (!cnt[y[u]] || !cnt[z[u]]) {
if (!cnt[y[u]] && cnt[z[u]]) printf("Stack number %d is empty !\n\n", y[u]);
else if (cnt[y[u]] && !cnt[z[u]]) printf("Stack number %d is empty !\n\n", z[u]);
else if (!cnt[y[u]] && !cnt[z[u]]) printf("Stack %d and Stack %d are empty !\n\n", y[u], z[u]);
return 0;
} else if (y[u] == z[u]) {
printf("Select stack repeat !\n\n");
return 0;
} else {
cnt[y[u]]--;
cnt[z[u]]--;
for (int i = 1; i <= M; i++) stk[y[u]][i] = stk[y[u]][i + 1];
for (int i = 1; i <= M; i++) stk[z[u]][i] = stk[z[u]][i + 1];
u++;
}
}
}
}
for (int i = 1; i <= n; i++) {
if (cnt[i]) {
puts("All stacks are not empty !\n\n");
return 0;
}
}
system("cls");
puts("Accepted !\n");
return 0;
}
回复
共 9 条回复,欢迎继续交流。
正在加载回复...