码迷,mamicode.com
首页 > 其他好文 > 详细

Permutation

时间:2017-11-11 17:53:07      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:tle   ica   str   bre   inpu   测试   ...   pac   mono   

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

标签:tle   ica   str   bre   inpu   测试   ...   pac   mono   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!