QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#820871 | #9891. Traveler | N_z_ | AC ✓ | 33ms | 3772kb | C++23 | 630b | 2024-12-19 08:52:01 | 2024-12-19 08:52:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int>vis(n+1);
vis[0]=vis[1]=1;cout<<1;
auto run=[&](int pos){if(!vis[pos])cout<<' '<<pos,vis[pos]=1;};
int x=1;
while(x<=n)
{
run(x);
if(n/2==x)
{
if(n&1^1)run(n),n--;
for(int x=n;!vis[x];x-=2)
run(x),run(x/2),run(x-1);
break;
}
if(!vis[x-1])x--;else x*=2;
}
cout<<'\n';
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
2 2 9
output:
1 2 1 2 4 9 8 7 3 6 5
result:
ok ok 2 cases.
Test #2:
score: 0
Accepted
time: 33ms
memory: 3772kb
input:
999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
1 1 2 1 3 2 1 2 4 3 1 2 5 4 3 1 2 4 3 6 5 1 2 4 3 7 6 5 1 2 4 8 7 3 6 5 1 2 4 9 8 7 3 6 5 1 2 4 3 6 5 10 9 8 7 1 2 4 3 6 5 11 10 9 8 7 1 2 4 3 6 12 11 5 10 9 8 7 1 2 4 3 6 13 12 11 5 10 9 8 7 1 2 4 3 6 5 10 9 8 7 14 13 12 11 1 2 4 3 6 5 10 9 8 7 15 14 13 12 11 1 2 4 3 6 5 10 9 8 16 15 7 14 13 12 11 ...
result:
ok ok 999 cases.
Extra Test:
score: 0
Extra Test Passed