codeforces_304C_数学题
2 seconds
256 megabytes
standard input
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?
The first line contains a single integer n (1 ≤ n ≤ 105).
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.
5
1 4 3 2 0
1 0 2 4 3
2 4 0 1 3
2
-1
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_数学题的更多相关文章
- ytu 2558: 游起来吧!超妹!(水题,趣味数学题)
2558: 游起来吧!超妹! Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 7 Solved: 3[Submit][Status][Web Board ...
- sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
- python解无忧公主数学题107.py
python解无忧公主数学题107.py """ python解无忧公主数学题107.py http://mp.weixin.qq.com/s?__biz=MzI5ODE ...
- python解无忧公主数学题108
""" python解无忧公主数学题108回文.py 题目来源: http://mp.weixin.qq.com/s?__biz=MzI5ODEwMDQyNw==& ...
- HDU 圆桌会议 - 数学题
圆桌 题意就是每分钟可以将相邻的两个人的位置互换一下 , 问你 ,几分钟可以将所有人的位置互换成 原先的 B 在A的右边 C在A的左边 , 换成现在的 C 在A 的右边 , B 在 A 的 ...
- HDU 2529 Shot (物理数学题)
题目 解题过程: //物理数学题 #include<stdio.h> #include<string.h> #include<algorithm> using na ...
- 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) /********* ...
- ACM之数学题
数学题,始终记得,第一次被带飞师大校赛以及省赛,毫无例外的在数学题上卡死....因此,现在开始,有意识的保留遇见的数学题...(下列知识点按遇见先后顺序排列: 1欧拉公式 欧拉公式的用处是,找出小于N ...
- hdu 5587 Array 数学题
Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...
随机推荐
- leetcode02-Add Two Numbers之beats98.68%Java版本号
我的leetcode之旅,该篇章主要完毕使用Java实现算法. 这是第二篇Add Two Numbers 所有代码下载: Github链接:github链接,点击惊喜; 写文章不易.欢迎大家採我的文章 ...
- javascript遍历数组的两种方法
var array=new Array(); array [0]="北京"; array [1]="天津"; ...//solution 1 for(var i ...
- Lunix
1.Lunix系统登录.重启.关闭 ①.登录 ②.重启 ③.关闭:shutdown [选项][时间][警告信息] -k 向所有用户发出警告信息 -r 关机后立即重启 -h 关机后不重新启动 -f 快速 ...
- NSSet所有API学习。
/****************集合(NSSet)和数组(NSArray)有相似之处,都是存储不同的对象的地址.只是NSArray是有序的集合,NSSet是无序的集合,同一时候NSSet能够保证数据 ...
- VS2010打开2012项目(转载)
原文出处:http://www.cnblogs.com/johnsony/p/Version2012To2010.html vs2012 出来了,但是MS还是一如既往的向上兼容. 废话不多说,直接主题 ...
- 【bzoj1269】[AHOI2006]文本编辑器editor
在bzoj上乱翻,发现了可持久化并查集,然后baidu了一下,发现一种叫rope的东西. !!!真的太爽了!!! 直接上代码,感受一下(也是蒯来的). 由于rope的底层实现,in ...
- java异常——重新抛出异常
有时候希望把刚捕获的异常重新抛出,尤其是在使用Exception捕获所有异常的时候.既然已经得到了对当前异常对象的引用,可以直接把它重新抛出: catch(Exception e){ System.o ...
- Ural 1382 2SAT
ural1382 直接套用 2SAT模板 缩点 拓扑排序... #include<iostream> #include<cstdio> #include<cstdlib& ...
- POJ1584 A Round Peg in a Ground Hole 凸包判断 圆和凸包的关系
POJ1584 题意:给定n条边首尾相连对应的n个点 判断构成的图形是不是凸多边形 然后给一个圆 判断圆是否完全在凸包内(相切也算) 思路:首先运用叉积判断凸多边形 相邻三条边叉积符号相异则必有凹陷 ...
- 用msys1.0+mingw gcc4.7.1编译libodb(C++ ORM)
这里主要使用的是libodb 对sqlite数据库的支持. (1)下载编译sqlite3,当初编译go-sqlite3的时候下载过sqlite3,就直接拿过来用了. start msys.bat gc ...