HDU 6235 2017-CCPC-哈尔滨站 Permutation(简单模拟)

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

题意:

pi%(|pi-pi-2|)==0。

题解:

很简单。看代码就好了。

#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int lb=1,ub=(n+1)/2+1;
        while(1)
        {
            if(lb<=(n+1)/2)
                cout<<lb++<<' ';
            else
                break;
            if(ub<=n)
                cout<<ub++<<' ';
            else
                break;
        }
        cout<<endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/orion7/p/7821018.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值