HDU 6235.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 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 哈尔滨赛区网络赛——测试专用
 
 

题意就是给出的n,从1到n,满足条件pi0(mod|pipi2|) 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 }

 队友太厉害啦,%%%。

 
 
 
 

转载于:https://www.cnblogs.com/ZERO-/p/7819862.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值