HDU - 6235 Permutation (2017CCPC哈尔滨 思维)
2017-11-12 19:51
405 查看
Permutation
Problem DescriptionA 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 given n.
Input
The first line is the number of test cases.
For each test case, one single line contains a positive integer n(3≤n≤105).
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.
Sample Input
1
6
Sample Output
1 3 2 6 4 5
题意:很简单。要注意是排列,就所有数字只能用一次。
解题思路:任何数模1,都为0.所以……看代码……
#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long int ll;
int a[100005];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
a[1]=1;
if(n%2)
a[2]=n/2+2;
else
a[2]=n/2+1;
for(int i=3;i<=n;i++)
a[i]=a[i-2]+1;
for(int i=1;i<n;i++)
cout<<a[i]<<" ";
cout<<a
<<endl;
}
return 0;
}
相关文章推荐
- HDU - 6237 A Simple Stone Game (2017CCPC哈尔滨站 思维)
- 2017CCPC哈尔滨 F:Permutation(构造)
- 2017多校第一场 HDU 6044 Limited Permutation 思维,计数,DFS
- hdu 6235 Permutation
- 2017ccpc哈尔滨 hdu 6231 B k-th number 题解 二分答案+尺取法
- E. Jeff and Permutation----思维题
- HDU 6044 Limited Permutation(递归)
- hdu 6048 Puzzle 思维(8数码问题
- hdu 3283 The Next Permutation
- hdu 4883 思维题
- HDU 6233 X-Men 哈尔滨现场赛D题
- 2016 Multi-University Training Contest 4 hdu 5775 Bubble Sort【树状数组+思维】
- HDU-6188 Duizi and Shunzi(思维)
- HDU 5665 Lucky(思维题)【BC】
- hdu 3811 Permutation
- hdu 5805 简单思维题
- hdu 4803 贪心/思维题
- HDU 5969 思维题
- hdu 2583 permutation
- CS 400 Digit Permutation 思维+拓扑序