原题链接: https://codeforces.com/problemset/problem/359/B
测试样例
Input
1 0
Output
1 2
Input
2 1
Output
3 2 1 4
Input
4 0
Output
2 7 4 6 1 3 5 8
题意: 给你个正整数和,其中,你需要找到~的排列数组,使得
。
解题思路: 由于,所以我们如果以为相邻之差的话自然也是可以达成任务需求的,所以按照的值一次模拟编排即可。
AC代码
/*
*
*
*/
//POJ不支持
using namespace std;
const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e5;//限定值。
typedef long long ll;
int n,k;
int main(){
while(cin>>n>>k){
//所有绝对值相加得到的与算数值相加再加+2k
int temp=2*k;
rep(i,1,2*n){
if(temp>=2){
cout<<i<<" "<<i+1<<" ";
temp-=2;
i++;
}
else{
cout<<i+1<<" "<<i<<" ";
i++;
}
}
cout<<endl;
}
return 0;
}