• 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
  • 相关阅读:
    docker 实现redis集群搭建
    ArrayList && LinkList
    ServletRequest、 HttpServletRequest、Request的联系与区别
    JSONObject例子
    使用SAXReader对XML进行操作
    JSON与XML的区别比较
    依赖注入(DI)和控制反转(IOC)
    Java 面试题:百度前200页都在这里了
    Java语言规范
    python+pandas+openpyxl下载xls illegalCharacterError
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6927840.html
Copyright © 2020-2023  润新知