CodeForces - 359B Permutation
2017-08-31 09:14
337 查看
CodeForces - 359B Permutation
题意:输入n与k,2k <= n,输出2*n个数,每个数都不相同且<=2*N,满足 思路:首先我们看k=0这种情况,当2,1,4,3.......2*n,2*n-1,满足k=0时,且两个式子的值都为n, 把这些数分为n对,如果交换其
中一对的位置,前一个式子的值不变,后一个式子的值减小了2,所以插值就变为了2,所以我们只要交换k对数,第二个式子的值为n-
2k, 差值就变为2*k。
#include<iostream> using namespace std; int main(void) { int n,k; cin>>n>>k; int flag=0; for(int i=1;i<=k;i++) { if(!flag) cout<<2*i-1<<" "<<2*i; else cout<<" "<<2*i-1<<" "<<2*i; flag=1; } for(int i=k+1;i<=n;i++) { if(!flag) cout<<2*i<<" "<<2*i-1; else cout<<" "<<2*i<<" "<<2*i-1; flag=1; } return 0; }
相关文章推荐
- Codeforces_359B_Permutation
- CodeForces 359B - Permutation(思维)
- CodeForces - 359B Permutation
- codeforces B. Permutation
- CodeForces - 361B D - Levko and Permutation 构造
- 【CodeForces】500B - New Year Permutation(Floyd)(贪心)
- 【CodeForces】622D - Optimal Number Permutation
- CodeForces - 864D Make a Permutation! 水题(用了优先队列)
- [codeforces]Levko and Permutation
- codeforces 676A Nicholas and Permutation
- CodeForces - 676A Nicholas and Permutation (模拟) 水
- CodeForces 785E Anton and Permutation (分块)
- 【CodeForces】500B - New Year Permutation(Floyd)(贪心)
- codeforces 553B B. Kyoya and Permutation(找规律)
- CodeForces 124 B.Permutations(next_permutation)
- [构造] Codeforces 804E Round #411 (Div. 1) E. The same permutation
- CodeForces-483C Diverse Permutation(构造)
- 【水题】CodeForces - 233A Perfect Permutation
- CodeForces 359B 构造
- 【CodeForces 618B 】Guess the Permutation(水题)