思维题,想到就秒杀,没想到或者想错方向了那么就完蛋了

0 1 2 3 4

1 2 3 4 0

你就会发现是可以的。

我经历了很久错误的思维,找到了一些性质

1.  ai+bi的和一定为一串从(n/2)递增的序列, 因为所有ai+bi(i从0-n-1)的和为一个固定的数,而得到的ci又要是0-n-1各一次。 所以也同时说明偶数的情况是不可行的。

然后稍加组合就可以发现将两个 0-n-1 的序列错开相加就可以得到结果。。

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.

Sample test(s)
input
5

output
1 4 3 2 01 0 2 4 32 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.

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;int g[100100];
int g1[100100];int main()
{int n;scanf("%d",&n);if(n%2==0) printf("-1");else{int cnt=0;for(int i=n/2;i<n;i++)g[cnt++]=i;for(int i=0;i<n/2;i++)g[cnt++]=i;for(int i=0;i<n;i++)g1[i]=(g[i]+i)%n;for(int i=0;i<n;i++)printf("%d ",i);printf("\n");for(int i=0;i<n;i++)printf("%d ",g[i]);printf("\n");for(int i=0;i<n;i++)printf("%d ",g1[i]);}return 0;
}

转载于:https://www.cnblogs.com/chenhuan001/archive/2013/05/13/3075870.html

Codeforces Round #183 (Div. 2) C相关推荐

  1. 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

    题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <c ...

  2. Codeforces Round #183 (Div. 2)

    A. Pythagorean Theorem II 暴力,\(O(n^2)\). B. Calendar 每个日期计算到0年1月1日的天数,相当于转化成前缀和形式. 闰年数计算\[\lfloor\fr ...

  3. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

  4. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  5. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  6. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  7. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  8. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  9. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

最新文章

  1. Java计算数学表达式(字符串形式)
  2. IE6 中的最大最小寬度和高度 css 高度 控制(兼容版本)
  3. 08_Android中的SimpleAdapter的使用
  4. (转)Cairngorm初学者入门教程 第三节--从使用Model Locator开始学起Cairngorm
  5. ARM中LDR伪指令与LDR加载指令
  6. pause pod 什么是pod_Kubernetes 自主式Pod清单 干货太多先马住慢慢看
  7. 在Docker上部署NGINX和NGINX Plus
  8. java 多线程并容器实现_跟着实例学习java多线程9-并发容器
  9. 什么是I/O地址,I/O端口和I/O端口地址?
  10. log4j和web.xml配置webAppRootKey 的问题(一个tomcat下部署多个应用)
  11. atmega328p引脚图_ATMega328P-PU芯片Arduino最小系统实验
  12. 语音识别算法、模型等解析
  13. 微软历史最高市值是多少?
  14. R语言使用ltm包计算cronbach‘s alpha(克朗巴哈系数法)实战:cronbach alpha(克朗巴哈系数法)是一种测量问卷或调查内部一致性的方法、cronbach‘s alpha解读
  15. WIN7下点击安全删除硬件没反应解决办法
  16. MXL90614红外线测温传感器
  17. 使用java开发spark实战
  18. Python数据分析和挖掘之入门理论+实操
  19. oracle连现金流量表都没有,现金流量表里面的数据地方都是空白的 没有数字
  20. Matlab学习第一天(注释、输入输出、清空工作区、清屏、向量矩阵表示和运算、字符串、求和求积函数、等差数列、特征值、判断语句、循环语句)

热门文章

  1. matlan数据分析库函数
  2. 不允许一个迭代的对象自己接着迭代下去(Python)【fronzenset】
  3. matlab条件判断配合输出
  4. GWT interface的使用例子
  5. [C#]关于override和new在重写方法时的区别
  6. mysql 主从单库单表同步 binlog-do-db replicate-do-db
  7. 【基环树DP】[NOI2012]迷失游乐园
  8. Item 16: 让const成员函数做到线程安全
  9. forward 和redirect的区别
  10. 腾讯2013暑期实习笔试面试总结