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 ...
随机推荐
- hdu oj 1285 确定比赛名次
hdu oj 1285 确定比赛名次 题目: 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Linux下,PHP的SESSION不起作用的问题
改动SESSION目录的权限就能够了. 先找到SESSION目录, 然后 chmod -R 777 /var/lib/php/session 假设没有此目录,则新建此目录 mkdir -R 777 / ...
- TQ2440 学习笔记—— 1、Windows平台下开发工具安装与环境建立
板子:广州天嵌公司的TQ2440,处理器为三星的S3C2440 1.开发工具的安装与环境建立 系统:win7 64位 SecureCRT软件:该软件能够取代Windows中的超级终端,是个非常好的串 ...
- (一)Java 入门教程
Java 入门教程 Java 是由Sun Microsystems公司于1995年5月推出的高级程序设计语言. Java可运行于多个平台,如Windows, Mac OS,及其他多种UNIX版本的系统 ...
- HDU 1505 City Game(DP)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- html5 弹性布局
html5 弹性布局 一.移动开发常用技巧 Viewport基本知识 设置布局Viewport的各种信息1.width=device-width: 设置Viewport视口宽度等于设备宽度2.init ...
- Minimizing Maximizer
题意: 最少需要多少个区间能完全覆盖整个区间[1,n] 分析: dp[i]表示覆盖[1,i]最少需要的区间数,对于区间[a,b],dp[b]=min(dp[a...b-1])+1;用线段树来维护区间最 ...
- http访问方式
package com.m.billingplug.util; import java.io.IOException; import java.net.UnknownHostException; im ...
- BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay
BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...
- 记录一次Mysql死锁排查过程
背景 以前接触到的数据库死锁,都是批量更新时加锁顺序不一致而导致的死锁,但是上周却遇到了一个很难理解的死锁.借着这个机会又重新学习了一下mysql的死锁知识以及常见的死锁场景.在多方调研以及和同事们的 ...