【水题】CodeForces - 233A Perfect Permutation
2017-06-15 09:30
323 查看
Problem Description
给你一个n,让你制造出一个序列满足ppi = i &&pi ≠ i. 想要满足ppi = i && pi ≠ i.就是两个下标交换一下位置。所以n为奇数的时候是满足不了的。n为偶数的时候,直接交换输出序列就好了。
代码:偶数直接2,1,4,3….的输出就可以满足序列了
给你一个n,让你制造出一个序列满足ppi = i &&pi ≠ i. 想要满足ppi = i && pi ≠ i.就是两个下标交换一下位置。所以n为奇数的时候是满足不了的。n为偶数的时候,直接交换输出序列就好了。
代码:偶数直接2,1,4,3….的输出就可以满足序列了
#include<bits/stdc++.h> using namespace std; int main() { int n; while(~scanf("%d", &n)) { if(n % 2 != 0) { //奇数 printf("-1\n"); } else //偶数 { int c = 2; printf("%d", c); printf(" %d", c - 1); c = c + 2; for(int i = 1; i <= (n - 2) / 2; i++) { printf(" %d", c); printf(" %d", c - 1); c = c + 2; } printf("\n"); } } }
相关文章推荐
- CodeForces 233A Perfect Permutation
- 【CodeForces 618B 】Guess the Permutation(水题)
- CodeForces - 864D Make a Permutation! 水题(用了优先队列)
- codeforces 676A A. Nicholas and Permutation(水题)
- Codeforces 233A Perfect Permutation(完美序列,水题)
- codeforces 231 A Team(水题)
- codeforces 133A HQ9+(字符串水题)
- CodeForces--609C --Load Balancing(水题)
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- POJ 2470 Ambiguous permutation(我的水题之路——位置和值的队列)
- CodeForces 515C Drazil and Factorial (水题)
- CodeForces--621A--Wet Shark and Odd and Even(数学水题)
- 平常水题 - Codeforces 659D Bicycle Race(几何公式)
- Codeforces 278C Learning Languages【并查集】水题
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
- codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)
- Codeforces 851A - Arpa and a research in Mexican wave - 水题
- Codeforces 632B Alice, Bob, Two Teams 【水题】
- CodeForces 689A Mike and Cellphone (模拟+水题)
- Codeforces--630A--Again Twenty Five! (水题)