最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#144(Div.2)-A.PerfectPermutation_html/css

来源:懂视网 责编:小采 时间:2020-11-27 15:57:29
文档

CodeforcesRound#144(Div.2)-A.PerfectPermutation_html/css

CodeforcesRound#144(Div.2)-A.PerfectPermutation_html/css_WEB-ITnose:Perfect Permutation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation is a sequence of integers p1,p2。.。pn, consisting of n distinct positiv
推荐度:
导读CodeforcesRound#144(Div.2)-A.PerfectPermutation_html/css_WEB-ITnose:Perfect Permutation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation is a sequence of integers p1,p2。.。pn, consisting of n distinct positiv

Perfect Permutation

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A permutation is a sequence of integers p1,?p2,?...,?pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1,?p2,?...,?pn.

Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfectpermutation is such permutation p that for any i (1?≤?i?≤?n) (n is the permutation size) the following equations hold ppi?=?i and pi?≠?i. Nickolas asks you to print any perfect permutation of size n for the given n.

Input

A single line contains a single integer n (1?≤?n?≤?100) ? the permutation size.

Output

If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1,?p2,?...,?pn ? permutation p, that is perfect. Separate printed numbers by whitespaces.

Sample test(s)

input

output

-1

input

output

2 1 

input

output

2 1 4 3 





解题思路:贪心。直接构造。如果n为奇数,则不能构成满足要求的排列;否则,两个两个的构造,如2,1;4,3。。以此类推即可。







AC代码:

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x7fffffffint main(){ #ifdef sxk freopen("in.txt","r",stdin); #endif int n; while(scanf("%d",&n)!=EOF) { if(n&1){ printf("-1\n"); continue; } else{ for(int i=1; i

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

CodeforcesRound#144(Div.2)-A.PerfectPermutation_html/css

CodeforcesRound#144(Div.2)-A.PerfectPermutation_html/css_WEB-ITnose:Perfect Permutation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation is a sequence of integers p1,p2。.。pn, consisting of n distinct positiv
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top