A. 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 perfect permutation 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 np1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces.

Examples

input

1

output

-1

input

2

output

2 1

input

4

output

2 1 4 3 
  • 关键是两个公式:ppi = i and pi ≠ i.;把奇偶两位互换即可,当然n得是偶数;
  • #include <iostream>
    
    using namespace std;
    
    int main()
    {
    int n;
    cin >> n;
    if( n % 2 == 1 )
    {
    cout << -1 <<endl;
    }
    else
    {
    int i, a[101];
    for( i=1; i<=n; i++ )
    {
    if( i % 2 == 1 )
    {
    a[i] = i + 1;
    }
    else
    {
    a[i] = i - 1;
    }
    }
    for( i=1; i<n; i++ )
    {
    cout << a[i] << " ";
    }
    cout << a[i] << endl;
    }
    return 0;
    }

CodeForces - 233A Perfect Permutation的更多相关文章

  1. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

  2. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  3. CodeForces 923C Perfect Security

    C. Perfect Security time limit per test3.5 seconds memory limit per test512 megabytes inputstandard ...

  4. codeforces 483C.Diverse Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...

  5. Codeforces 986D Perfect Encoding FFT 分治 高精度

    原文链接https://www.cnblogs.com/zhouzhendong/p/9161557.html 题目传送门 - Codeforces 986D 题意 给定一个数 $n(n\leq 10 ...

  6. Codeforces 980D Perfect Groups 计数

    原文链接https://www.cnblogs.com/zhouzhendong/p/9074164.html 题目传送门 - Codeforces 980D 题意 $\rm Codeforces$ ...

  7. [CodeForces - 919B] Perfect Number

    题目链接:http://codeforces.com/problemset/problem/919/B AC代码: #include<cstdio> using namespace std ...

  8. Codeforces 948D Perfect Security(字典树)

    题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...

  9. Codeforces 285C - Building Permutation

    285C - Building Permutation 思路:贪心.因为每个数都不同且不超过n,而且长度也为n,所有排列只能为1 2 3 ......n.所以排好序后与对应元素的差值的绝对值加起来就是 ...

随机推荐

  1. delphi 在桌面屏幕上模拟鼠标单击

    delphi 在桌面屏幕上模拟鼠标单击 procedure TFrmUnicom.Button1Click(Sender: TObject); var oldPoint, newPoint: TPoi ...

  2. pandas读写excel

    import pandas as pd import numpy as np df = pd.read_csv("result.csv") # csv # df = pd.read ...

  3. [android] setOnTouchEvent 设置返回值为true 和 false的区别

    今天在做自定义的可选文本的 TextView 类时,用到了 View 类的 setOnTouchListener(OnTouchListener l)事件监听,在构造 OnTouchListener ...

  4. js控制图片放大缩小的简易版

    js代码: function bb_img_onmousewheel(e, o) { var zoom = parseInt(o.style.zoom, 10) || 100; zoom += eve ...

  5. day63-webservice 02.cxf环境搭建

    指定bin目录的目的是在docs窗口可以直接来执行这里面的命令. ANT这里面

  6. 535. Encode and Decode TinyURL 长短URL

    [抄题]: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problem ...

  7. opennebula kvm日志

    Fri Jul :: [InM][I]: Command execution fail: 'if [ -x "/home/oneadmin/tmp/one/im/run_probes&quo ...

  8. Python PyPI中国镜像

    from:http://blog.makto.me/post/2012-11-01/pypi-mirror from:http://www.pypi-mirrors.org/ from:http:// ...

  9. linux操作小技巧

    巧妙利用别称 alias,让工作更有效率 在我的个人目录下/home/zdwu,打开.bashrc文件进行修改: 将  ll='ls -alF' 改为 ll='ls -ahlF',是的观察的结果显示更 ...

  10. Swing自定义JScrollPane的滚动条设置,重写BasicScrollBarUI方法

    Swing自定义JScrollPane的滚动条设置,重写BasicScrollBarUI方法 摘自:https://blog.csdn.net/qq_31635851/article/details/ ...