C. Lucky Permutation Triple
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not.

A permutation triple of permutations of length n (a, b, c) is called a Lucky Permutation Triple if and only if . The sign ai denotes the i-th element of permutation a. The modular equality described above denotes that the remainders after dividing ai + bi by n and dividing ci by n are equal.

Now, he has an integer n and wants to find a Lucky Permutation Triple. Could you please help him?

Input

The first line contains a single integer n (1 ≤ n ≤ 105).

Output

If no Lucky Permutation Triple of length n exists print -1.

Otherwise, you need to print three lines. Each line contains n space-seperated integers. The first line must contain permutation a, the second line — permutation b, the third — permutation c.

If there are multiple solutions, print any of them.

Examples
input
5
output
1 4 3 2 0
1 0 2 4 3
2 4 0 1 3
input
2
output
-1
Note

In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:

  • ;
  • ;
  • ;
  • ;
  • .

In Sample 2, you can easily notice that no lucky permutation triple exists.

题目大意:对于一个整数n有元素是0--n-1的排列,求这样的排列3元组,他满足:
分析:

/* 证明有问题

当n是奇数:

n=1时,0,0,0;
0,1,2,……,n/2,……,n-2,n-1
1,2,3,……,n/2+1,……,n-1,0
1,3,5,……,n,……,2(n-1)-1,n-1 (除最后一个数字都是奇数)
第3行对n取模:1,3,5,……,0,……,n-3,n-1(除了n-1, 趋势:一半奇数,一半偶数)

当n是偶数:
因为偶数不会在取模后改变原数字的奇偶性,所以需要我们构造第三行的数字一半是奇数一半是偶数。
已知:
奇数+奇数=偶数 
偶数+偶数=偶数
奇数+偶数=奇数
所以需要有n/2对奇数+偶数 (1),n/2对同型相加 (2),然而在n是偶数的情况下奇数有n/2个,偶数也是n/2个,在满足(1)的条件下第一行的奇数用完了偶数,所以(2)不能满足。即偶数不能构造3元组。

*/

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n,num1[],num2[],num3[];
scanf("%d",&n);
if(n%==)
printf("-1\n");
else
{
for(int i=; i<n; i++)
num1[i]=i;
for(int i=; i<n; i++)
num2[i]=(i+)%n;
for(int i=; i<n; i++)
num3[i]=(num1[i]+num2[i])%n;
for(int i=; i<n; i++)
{
printf("%d",num1[i]);
if(i==n-)
printf("\n");
else
printf(" ");
}
for(int i=; i<n; i++)
{
printf("%d",num2[i]);
if(i==n-)
printf("\n");
else
printf(" ");
}
for(int i=; i<n; i++)
{
printf("%d",num3[i]);
if(i==n-)
printf("\n");
else
printf(" ");
}
}
return ;
}

codeforces_304C_数学题的更多相关文章

  1. ytu 2558: 游起来吧!超妹!(水题,趣味数学题)

    2558: 游起来吧!超妹! Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 7  Solved: 3[Submit][Status][Web Board ...

  2. sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)

    Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...

  3. python解无忧公主数学题107.py

    python解无忧公主数学题107.py """ python解无忧公主数学题107.py http://mp.weixin.qq.com/s?__biz=MzI5ODE ...

  4. python解无忧公主数学题108

    """ python解无忧公主数学题108回文.py 题目来源: http://mp.weixin.qq.com/s?__biz=MzI5ODEwMDQyNw==& ...

  5. HDU 圆桌会议 - 数学题

    圆桌   题意就是每分钟可以将相邻的两个人的位置互换一下 , 问你 ,几分钟可以将所有人的位置互换成    原先的  B 在A的右边 C在A的左边 , 换成现在的 C 在A 的右边 , B 在 A 的 ...

  6. HDU 2529 Shot (物理数学题)

    题目 解题过程: //物理数学题 #include<stdio.h> #include<string.h> #include<algorithm> using na ...

  7. HDU 2671 Can't be easier(数学题,点关于直线对称)

    题目 //数学题//直线 y = k * x + b//直线 ax+by+c=0; 点 (x0,y0); 点到直线距离 d = (ax0+by0+c)/sqrt(a^2+b^2) /********* ...

  8. ACM之数学题

    数学题,始终记得,第一次被带飞师大校赛以及省赛,毫无例外的在数学题上卡死....因此,现在开始,有意识的保留遇见的数学题...(下列知识点按遇见先后顺序排列: 1欧拉公式 欧拉公式的用处是,找出小于N ...

  9. hdu 5587 Array 数学题

    Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...

随机推荐

  1. openTSDB ConnectionManager: Unexpected exception from downstream java.io.IOException: Broken pipe

    openTSDB有这种错误: ConnectionManager: Unexpected exception from downstream for [id: 0xf85323a8, /10.65.3 ...

  2. Android学习笔记-listview实现方式之BaseAdapter

    listview是Android开发中最为常用的组件,这里我们就学习一下用BaseAdapter的方式实现listview, 主布局activity_main.xml是这样的: <LinearL ...

  3. OSS与文件系统的对比

    基本概念介绍_开发指南_对象存储 OSS-阿里云  https://help.aliyun.com/document_detail/31827.html 强一致性 Object 操作在 OSS 上具有 ...

  4. Windows10 Win键失灵的解决方法

    之前在Windows10出来的时候在使用过程中发现:按“Win键”调出开始菜单没有用.一点反应都没有.Win+R等这样的组合键也没用. 后来周年更新后,还是无法使用... 各种方法用尽啊.都不行啊! ...

  5. core.async中go的作用研究

    (defmacro go "Asynchronously executes the body, returning immediately to the calling thread. Ad ...

  6. YTU 2626: B 统计程序设计基础课程学生的平均成绩

    2626: B 统计程序设计基础课程学生的平均成绩 时间限制: 1 Sec  内存限制: 128 MB 提交: 427  解决: 143 题目描述 程序设计基础课程的学生成绩出来了,老师需要统计出学生 ...

  7. Bug分支(转载)

    转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178 ...

  8. SQLAlchemy 反向生成 model 模型

    前言 Django 反向生成的 model 模型的命令 :  python manager.py inspectdb SQLAlchemy / Flask-SQLAlchemy则是: pip3 ins ...

  9. bzoj1015星球大战(并查集+离线)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 5572  Solved: 2563 Descri ...

  10. 微服务下,使用ELK做日志收集及分析

    一.使用背景 目前项目中,采用的是微服务框架,对于日志,采用的是logback的配置,每个微服务的日志,都是通过File的方式存储在部署的机器上,但是由于日志比较分散,想要检查各个微服务是否有报错信息 ...