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. react 项目实战(五)渲染用户列表

    现在我们需要一个页面来展现数据库中记录的用户. 在/src/pages下新建UserList.js文件. 创建并导出UserList组件: import React from 'react'; cla ...

  2. APICloud平台的融云2.0集成

    融云2.0的官方文档地址:http://docs.apicloud.com/端API/开放SDK/rongCloud2 项目须要IM模块,最后还是选择了融云.在iOS原生开发中,融云sdk集成了聊天界 ...

  3. NDK开发,没有你想象的那么难

    NDK:Native Development Kit原生开发工具 NDK能干什么:NDK使得在android中,java能够调用C函数库. 为什么要用NDK:我们都知道.java是半解释型语言,非常e ...

  4. Android系统优化

    这些事实上就是优化rom 的一些实用小技巧. 认为非常多还是实用的. Build.prop (编辑 /system/build.prop 文件(须要root, 能够用文件管理器或者其它root exp ...

  5. 【bzoj4597】 [Shoi2016]随机序列

    可以发现加减号之间可以互相抵消. 真正加到答案里的只有一些前缀积. 记s[i]为a[1]*a[2]*a[3]...*a[i].那s[i]在答案中出现的次数就是2*3^(n-i-1); 修改一个数只会对 ...

  6. 自定义Notification实现例子

    1.自定义view: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...

  7. 洛谷P1514 引水入城——dfs

    题目:https://www.luogu.org/problemnew/show/P1514 搜索+DP: 自己想出来的方法第一次80分好高兴! 再改了改就A了,狂喜乱舞: 也就是 dfs,仔细一想第 ...

  8. IDEA中 Spark 读Hbase 报错处理:

    SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] // :: ERROR RecoverableZooKeepe ...

  9. python实现对excel数据进行修改/添加

    import osimport xlrdfrom xlutils.copy import copydef base_dir(filename=None): return os.path.join(os ...

  10. CSS3常用知识点

    CSS3常用知识点 1 css3选择器 1.1 属性选择器 /* E[attr~=val] 表示的一个单独的属性值 这个属性值是以空格分隔的*/ .attr2 a[class~="kawa& ...