zoukankan      html  css  js  c++  java
  • hust新人赛模拟20150407 C

    C - C
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Permutationp is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larger than n. We'll denote asn 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.

    Sample Input

    Input
    3 2
    Output
    1 3 2
    Input
    3 1
    Output
    1 2 3
    Input
    5 2
    Output
    1 3 2 4 5

    Hint

    By |x| we denote the absolute value of number x.

    题意是说找到找到一组n个由1..n组成的数列,且每个数字只出现一次

    满足每相邻的两项的差的绝对值一共有k种。

    找规律即可。不好描述,直接上代码吧。

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <cmath>
     6 using namespace std;
     7      int n,k;
     8      int tmp,p;
     9      const int N=1E5+7;
    10      int a[N];
    11 
    12 int main()
    13 {
    14 
    15      scanf("%d %d",&n,&k);
    16      for ( int i = 1; i <= n ; i++ )
    17         a[i] = i;
    18         tmp = k;
    19         p = 1;
    20      for ( int i = 2 ; i <= k+1  ; i++)
    21      {
    22          a[i] = a[i-1] + tmp*p;
    23          tmp--;
    24          p=p*-1;
    25      }
    26      for ( int i = 1 ; i < n ; i++ )
    27         printf("%d ",a[i]);
    28     printf("%d",a[n]);
    29 
    30     return 0;
    31 }
  • 相关阅读:
    python百度ai的银行卡识别代码
    python百度ai的身份证识别代码
    Linux下安装jupyter
    HADOOP 与 jupyterlab 链接
    csv文件数据导出到mongo数据库
    Contos7 常用命令
    centos 安装Python3 及对应的pip
    PHP 连接数据库
    java 注解学习记录
    java简单实现搜索指定后缀文件
  • 原文地址:https://www.cnblogs.com/111qqz/p/4403431.html
Copyright © 2011-2022 走看看