题解:CF2117B 缩小操作
缩小操作/Shrink
问题描述/Problem
给定从
解决方案/Solution
瞪大眼睛观察样例,发现删除最后留下的一定是 1 2 3 。此外,由于没有
所以,我们可以通过倒推的方式找出最优方案的规律。首先,为了让 1 3 5 6 4 2 。
给一个具体的删除过程:
1 3 5 6 4 2
1 3 5 - 4 2
1 3 - - 4 2
1 3 - - - 2
1 - - - - 2
'-' 代表已被删除的数
代码/Code
-O2 -std=c++11
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int T;
signed main()
{
cin>>T;
for(int t=1;t<=T;t++)
{
int n,a[200005];
memset(a,0,sizeof a);
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==1)
{
a[(i+1)/2]=i;
}
else
{
a[n-(i/2)+1]=i;
}
}
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
return 0;
}
Other/其他
codeforces 1029 div2 submission
没想到第一篇题解是红题
The End