zoukankan      html  css  js  c++  java
  • Codeforces 482A. Diverse Permutation

    Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,   p2,   ...,   pn.

    Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.

    Input

    The single line of the input contains two space-separated positive integers nk (1 ≤ k < n ≤ 105).

    Output

    Print n integers forming the permutation. If there are multiple answers, print any of them.

    找规律咯

      按照     ...3 k-1 2 k 1 k+1 k+2 ... n

      的排法

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include <string>
    #include <sstream>
    #include <map>
    #include <cmath>
    #include <algorithm>
    #include <iomanip>
    #include <stack>
    #include <queue>
    #include <set>
    using namespace std;
    typedef long long LL;
    #define MOD 1000000007
    int n,k;
    int a[100005];
    int main(){
      // freopen("test.in","r",stdin);
      cin >> n >> k;
      int now = 1,nowk = k,dist = k,direct = 1,total(0);
      while (dist >= 1){
        if (direct == 1){
          total ++;
          a[total] = now; now ++;
        }
        else {
          total ++;
          a[total] = nowk; nowk --;
        }
        direct = 1 - direct;
        dist --;
      }
      for (int i=total;i>=1;i--){
        cout << a[i] << " ";
      }
      for (int i=k+1;i<=n;i++){
        cout << i << " ";
      }
      return 0;
    }
    View Code
  • 相关阅读:
    【vim】 match手动设置想高亮的关键字
    【git】add代码之前查看大致修改代码量
    语法错误和语义错误区别
    PIL安装方法
    dlib的安装
    python使用pip安装模块出现ReadTimeoutError: HTTPSConnectionPool的解决方法
    shape与reshape区别
    操作系统复习灭火思维导图
    sql语句模糊查询
    python中sort和sorted函数的区别
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6927840.html
Copyright © 2011-2022 走看看