Permutation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Special Judge
Problem Description
A permutation p1,p2,...,pn of 1,2,...,n is called a lucky permutation if and only if p≡0(mod|p−p|) 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 p,p,...,p.
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
Source
2017 ACM/ICPC 哈尔滨赛区网络赛——测试专用
题意就是给出的n,从1到n,满足条件p≡0(mod|p−p|) for i=3...n.
就是p%(p-p)==0就可以。
一开始想的好麻烦,队友太强啦,直接%1就可以啦,只要要计算的两个数相差为1就可以。
看代码就知道了,后面的数顺序和逆序都无所谓的。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N];
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int h=,k=n;
for(int i=;i<=n;i+=)a[i]=h++;
for(int i=;i<=n;i+=)a[i]=k--;
for(int i=;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
}
return ;
}
队友太厉害啦,%%%。