首页 > 其他 > 详细

Permutation

时间:2017-11-11 17:20:00      阅读:637      评论:0      收藏:0      [点我收藏+]

Permutation

 

Problem Description
A permutation p1,p2,...,pn of 1,2,...,n is called a lucky permutation if and only if pi0(mod|pipi2|) 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(3n105).
 

 

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
 

 

Source
2017 ACM/ICPC 哈尔滨赛区网络赛——测试专用
 
找规律
先输出奇数 1 2 3 4 5...
偶数就用剩下的依次加1
 
 
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     int t, n;
 6     cin >> t;
 7     while(t--) {
 8         cin >> n;
 9         int a = 1, b = n/2+1 +((n&1)?1:0);
10         for(int i = 1; i <= n; i ++) {
11             if(i&1){
12                 printf("%d%c",a++,i==n?\n: );
13             } else {
14                 printf("%d%c",b++,i==n?\n: );
15             }
16         }
17     }
18     return 0;
19 }

 

Permutation

原文:http://www.cnblogs.com/xingkongyihao/p/7819442.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!