hdu 6235 Permutation
来源:互联网 发布:大数据细分领域 编辑:程序博客网 时间:2024/06/07 21:08
Permutation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 179 Accepted Submission(s): 132
Special Judge
Problem Description
A permutation p1,p2,...,pn of 1,2,...,n is called a lucky permutation if and only if pi≡0(mod|pi−pi−2|) for i=3...n .
Now you need to construct a lucky permutation with a givenn .
Now you need to construct a lucky permutation with a given
Input
The first line is the number of test cases.
For each test case, one single line contains a positive integern(3≤n≤105) .
For each test case, one single line contains a positive integer
Output
For each test case, output a single line with n numbers p1,p2,...,pn .
It is guaranteed that there exists at least one solution. And if there are different solutions, print any one of them.
It is guaranteed that there exists at least one solution. And if there are different solutions, print any one of them.
Sample Input
16
Sample Output
1 3 2 6 4 5
题意:构造满足pi%(|pi-pi-2|)==0的序列。
思路:i和i+2的奇偶性是相同的,所以奇偶序列是互不干扰的。根据pi%(|pi-pi-2|)==0推出,只要奇子序列的数和偶子序列的数分别是相邻的自然数就行了。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); int num1=1,num2=(n+1)/2+1,i=1; while(i<=n) { if(i%2==1) { if(i==1) printf("%d",num1++),i++; else printf(" %d",num1++),i++; } if(i%2==0&&i<=n) printf(" %d",num2++),i++; } printf("\n"); } return 0;}
阅读全文
0 0
- hdu 6235 Permutation
- hdu 4345 Permutation
- Hdu 4345 Permutation
- HDU 2583 permutation
- hdu 2404 Permutation Recovery
- HDU 4917 Permutation
- hdu-2583 permutation
- HDU 3664 Permutation Counting
- HDU 4345 Permutation dp
- HDU 2583 permutation
- HDU 3667 Permutation Counting
- hdu 5753 Permutation Bo
- HDU 5753 Permutation Bo
- HDU-5753-Permutation Bo
- HDU 5753 Permutation Bo
- 【HDU】5753 Permutation Bo
- HDU 5789 Permutation
- 【HDU】5789 Permutation【dp】
- 同一台电脑教你配置多个Tomcat的环境变量
- JVM系列(一)垃圾回收算法
- SpringBoot的入门搭建(一)
- NavigationView中获取headerLayout的方法
- 牧函 | 十字架和垃圾场
- hdu 6235 Permutation
- JDBC快速保存数据到MySQL
- 原型对象的作用及原型对象的用法
- Hangover
- 简单泛型DAO的实现
- IMX6的LINUX下的IIC驱动(一)
- python编写spark的配置
- list去除重复元素的两种方法
- STM32寄存器列表 RCC时钟相关寄存器