QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#820033 | #9891. Traveler | dxbt | AC ✓ | 31ms | 3696kb | C++14 | 773b | 2024-12-18 19:07:41 | 2024-12-18 19:07:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
bool vis[1000009];
int main()
{
int T;
cin>>T;
while(T--)
{
int x;
cin>>x;
int nw=1,sp=1<<__lg(x);
cout<<1;
if(x==1)goto loop;
while(1)
{
if(nw!=1)cout<<' '<<nw;vis[nw]=1;
if(nw*2==x||nw*2+1==x)break;
if(nw>1&&!vis[nw-1]) --nw;
else nw=nw*2;
}
nw=x;
while(1)
{
cout<<' '<<nw;vis[nw]=1;
if(nw*2+1==sp-1&&!vis[nw*2+1])nw=nw*2+1;
else if(nw*2<=x&&!vis[nw*2])nw<<=1;
else if(nw-1==sp&&!vis[nw-1])nw--;
else if(nw>1&&!vis[nw/2])nw/=2;
else if(nw>1&&!vis[nw-1])nw--;
else break;
}
for(int i=1;i<=x;++i)if(!vis[i])
{
cerr<<'\n'<<i<<'-'<<x<<"=x\n";
exit(0);
}
for(int i=1;i<=x;++i)vis[i]=0;
loop:;
cout<<'\n';
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 31ms
memory: 3696kb
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