cf#209- B - Permutation-构造

http://codeforces.com/problemset/problem/359/B

给一个1-2n的序列,让你构造出n: .的序列

给你n,k     


先按2n到1排列,然后每次只需要交换前n-k对的位置即可




#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001; 
int min(int a,int b)
{return a<b?a:b;} 
int max(int a,int b)
{return a>b?a:b;}

int n,k;
int tm[2*50005];

int main()
{ 
	int i,j;

	scanf("%d%d",&n,&k);
	
	for (i=2*n;i>=1;i--)
		tm[i]=i;
	
	for (i=1;i<=n-k;i++)
	{
		int j=n-i+1;
		swap(tm[2*j],tm[2*j-1]);
	}
	for (i=2*n;i>=1;i--)
	{
		if (i!=2*n) printf(" ");
	printf("%d",tm[i]);
	}
	printf("\n");
	
	
	
	
	
	return 0;
	
}


你可能感兴趣的:(cf#209- B - Permutation-构造)