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
  • 相关阅读:
    OpenCV 创建Mat图像
    OpenCV Mat数据类型及位数总结
    OpenCV 使用at和ptr指针访问像素的区别
    OpenCV 16位深度图片显示并保存
    PyCharm 安装教程(Windows)
    Qt 安装图解(Windows平台)
    Qt 下载(多种下载通道+所有版本)
    QtCreator怎样编辑运行Python脚本
    Python 怎么运行代码
    Qt for Python 怎样搭建开发环境
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6927840.html
Copyright © 2011-2022 走看看