Permutation-水题-2017中国大学生程序设计竞赛-哈尔滨站-重现赛

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 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

Source

2017 ACM/ICPC 哈尔滨赛区网络赛——测试专用

题意就是给出的n,从1到n,满足条件pi≡0(mod|pi?pi?2|) for i=3...n.

就是pi%(pi-pi-2)==0就可以。

一开始想的好麻烦,队友太强啦,直接%1就可以啦,只要要计算的两个数相差为1就可以。

看代码就知道了,后面的数顺序和逆序都无所谓的。

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+10;
 4 int a[N];
 5 int main(){
 6     int t,n;
 7     scanf("%d",&t);
 8     while(t--){
 9         scanf("%d",&n);
10         int h=1,k=n;
11         for(int i=1;i<=n;i+=2)a[i]=h++;
12         for(int i=2;i<=n;i+=2)a[i]=k--;
13         for(int i=1;i<=n;i++)
14             printf("%d ",a[i]);
15         printf("\n");
16     }
17     return 0;
18 }

队友太厉害啦,%%%。

时间: 2024-11-08 21:50:39

Permutation-水题-2017中国大学生程序设计竞赛-哈尔滨站-重现赛的相关文章

A Simple Stone Game-找素因子(欧拉函数)-2017中国大学生程序设计竞赛-哈尔滨站-重现赛

A Simple Stone Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description After he has learned how to play Nim game, Bob begins to try another ston

2017中国大学生程序设计竞赛-哈尔滨站 H - A Simple Stone Game

A Simple Stone Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1526    Accepted Submission(s): 346 Problem Description After he has learned how to play Nim game, Bob begins to try another

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff(几何找规律)

Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in CaoHaha's hand.As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.But now,hi

2017中国大学生程序设计竞赛 - 女生专场(dp)

Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 701 Accepted Submission(s): 265 Problem Description HDU's n classrooms are on a line ,which can be considered as a number line. Eac

2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1146    Accepted Submission(s): 491 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single

2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 567    Accepted Submission(s): 210 Problem Description Little Q is crazy about graph theory, and now he creates a game about grap

2017中国大学生程序设计竞赛 - 网络选拔赛 1004

A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which h

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做一个数位DP就好了.dp[jz][start][cur][state]表示jz进制下以start位起始到cur位状态为state(1表示已经回文,0表示没有回文)时回文数的个数. #include <bits/stdc++.h> using namespace std; typedef long