zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Angularjs html文本显示
    .net与.net core学习目录
    数据库学习目录
    WCF学习目录
    sql学习目录
    EF学习目录
    git for Windows
    图谱论(Spectral Graph Theory)基础
    2017机器学习相关会议时间
    数值分析教材统计
  • 原文地址:https://www.cnblogs.com/orion7/p/7821018.html
Copyright © 2011-2022 走看看