题解
2023-07-07 13:20:18
发布于:上海
80阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int t; scanf("%d", &t);
for (int i=1; i<=t; i++) {
int n; scanf("%d", &n);
int c = n;
int *a = new int[n+1]();
Loop:
if (c <= 3) goto END;
for (int j = 1, cnt = 0; j <= n; j++) {
if (a[j] == 0) {
cnt ++ ;
if (cnt == 2) {
cnt = 0;
a[j] = 1;
c--;
}
}
}
if (c<=3) goto END;
for (int j = 1, cnt = 0; j <= n; j++) {
if (a[j] == 0) {
cnt ++ ;
if (cnt == 3) {
cnt = 0;
a[j] = 1;
c--;
}
}
}
if (c>3) goto Loop;
END:
bool first = true;
for (int j=1; j<=n; j++) {
if (!a[j] && first) { printf("%d", j); first = !first; }
else if (!a[j]) printf(" %d", j);
}
putchar('\n');
delete []a;
}
return 0;
}
这里空空如也
有帮助,赞一个