cf B. Permutation

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 int a[100010];
 7 int main()
 8 {
 9     int n,k;
10     scanf("%d%d",&n,&k);
11     for(int i=1; i<=2*n; i++)
12     {
13         a[i]=i;
14     }
15     for(int i=1; i<=k; i++)
16     {
17         swap(a[2*i-1],a[2*i]);
18     }
19     for(int i=1; i<=2*n; i++)
20     {
21         if(i==1) printf("%d",a[i]);
22         else printf(" %d",a[i]);
23     }
24     printf("\n");
25     return 0;
26 }

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

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 int n,k;
 7
 8 int main()
 9 {
10     while(scanf("%d%d",&n,&k)!=EOF)
11     {
12        printf("%d",k+1);
13        for(int i=1; i<=2*n; i++)
14        {
15            if(i!=k+1) printf(" %d",i);
16        }
17        printf("\n");
18     }
19     return 0;
20 }

时间: 2024-11-06 16:12:55

cf B. Permutation的相关文章

CF 1033C Permutation Game 拓扑+排序

题意:一个全排列,alice可以从某一个数出发,从i走到j的条件是: a[j]>a[i],而且从i到j要符合|i-j|%a[i]=0,若alice在该数有必胜的策略,输出B,否则A 思路,拓扑排序+博弈论(这题让我做的太迷了刚刚) ,用邻接表连接该数与其他数的关联,如果一开始入度为0的,即alice选择该点后,对方无法走去另一个点,alice会赢,把它们坐标存进一个数组里,再把它们连边进行分析,就可以判断出谁输谁赢,详情可看代码. #include <iostream> #include

CF 275(div.1) A Diverse Permutation

Diverse Permutation 题意:一个1~n的无重复整数序列,要求打印其中一种排列,使新序列相邻两项之差的绝对值去重后的个数刚好为k个     (1 <= k < n <= 10^5) 输入:n,k 输出:新序列 思路:想了一下,先考虑k最大和k最小取值时的序列排列情况 1) k最大时:k = n-1  序列:1,n,2,n-1,3,n-2.... 相邻两项绝对值差:n-1,n-2,n-3...1 2) k最小时:k = 1     序列:1,2,3...n | n,n-1,

CF 500 B. New Year Permutation 并查集

User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible. Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≤ k

CF785CAnton and Permutation(分块 动态逆序对)

Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once. One day Anton got a new permutation and

codeforces Goodbye2018 C. New Year and the Permutation Concatenation 傻瓜解法找规律+打表

这是goodbye2018的D题,红包赛第一场的C题 是我打的第一场CF 不知道为什么每次一补到这一场我就要强调一遍这是我的第一场CF...... .... .... 真矫情 不过还挺有仪式感的,嗯嗯~ o( ̄▽ ̄)o 看题吧 这题是肯定有公式的,不然这么乱七八糟的真的很难找规律,而且题目的名字就是permutation concatenation 这个题目真的很坏,只给了n=3时ans=9:n=4时ans=56: 其实如果知道了n=5时,ans=395,问题就迎刃而解了 我的方法跟官方题解的不

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是

CF with friends and user&#39;s influence considered on NYC data(updated Aug,11st)

Here is the code link: https://github.com/FassyGit/LightFM_liu/blob/master/U_F1.py I use NYC data as other experimens. The split of the training data was seperated by the timeline, and I have normalised the interaction matrix by replacing the checkin

31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replaceme

CF 750

今天CF打的块残废了     就是一废物 A 在24点之前到 直接模拟即可 #include<stdio.h> #include<algorithm> #include<cstring> #include<string> #include<cmath> using namespace std; #define LL long long #define MAXN 1010 #define inf 1000000000.0 int main() {