Diverse Permutation

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

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.

 #include <stdio.h>
#include <string.h>
int main()
{
int n,k;
int i,j;
int a[];
while(scanf("%d %d",&n,&k)!=EOF)
{
memset(a,,sizeof(a));
int j=k+,num=;
a[]=;
printf("");
while(k)
{
if(num-k> && a[num-k]==)
{
printf(" %d",num-k);
num=num-k;
a[num]=;
}
else
{
printf(" %d",num+k);
num=num+k;
a[num]=;
}
k--;
}
for(i=j;i<=n;i++)
{
printf(" %d",i);
}
printf("\n");
}
return ;
}

CodeForces 483C Diverse Permutation的更多相关文章

  1. codeforces 483C.Diverse Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...

  2. codeforces C. Diverse Permutation

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. [Codeforces 482A] Diverse Permutation

    [题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...

  4. codeforces C. Diverse Permutation(构造)

    题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...

  5. Codeforces 482 - Diverse Permutation 构造题

    这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ....... ...

  6. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  7. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  8. Codeforces Round #275(Div. 2)-C. Diverse Permutation

    http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...

  9. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

随机推荐

  1. 通过HP Loadrunner VuGen来录制安卓的应用

    作者:Richard Pal       来自:perftesting           翻译:Elaine00 通过这篇文章,我将介绍如何通过HP Loadrunner VuGen来测试一个安卓应 ...

  2. 好用的 diskpart 命令,操作磁盘分区,并创建 EFI 引导分区

    进入 win8 pe, 或在安装 win8 选择安装磁盘分区时按 shift+F10,都是可能用到 diskpart 去操作的时候. 进入cmd后, diskpart 进入 list disk---- ...

  3. Linux下串口编程【转】

    本文转载自:http://blog.csdn.net/w282529350/article/details/7378388 /************声明:本人只是见到这篇文章对我帮助很大才转载的,但 ...

  4. linux问题汇总---如何生成密钥对

    准备:2台机器,ip分别为:192.168.0.195     192.168.1.210目的:通过195ssh远程访问210.无需输入密码 1.首先在195上生成密钥对.#cd /root/.ssh ...

  5. dom4j读写XML文件

    XML文件格式: <?xml version="1.0" encoding="UTF-8"?> <company> <employ ...

  6. Linux 编程中的API函数和系统调用的关系【转】

    转自:http://blog.chinaunix.net/uid-25968088-id-3426027.html 原文地址:Linux 编程中的API函数和系统调用的关系 作者:up哥小号 API: ...

  7. CentOS 7安装Gnome GUI 图形界面

    当你安装centos服务器版本的时候,系统默认是不会安装 CentOS 的图形界面程序的,比如:gnome或者kde, 那么如果你想在图形界面下工作的话,可以手动来安装CentOS Gnome GUI ...

  8. crontab 日志备份定时任务

    -l选项,查看当前用户的所有定时任务: [xiluhua@vm-xiluhua][/home]$ crontab -l * * * * * /home/xiluhua/shell_script/log ...

  9. PHP弱类型安全问题的写法和步骤

    鉴于目前PHP是世界上最好的语言,PHP本身的问题也可以算作是web安全的一个方面.在PHP中的特性就是弱类型,以及内置函数对于传入参数的松散处理.本篇文章主要就是记录我在做攻防平台上面遇到的PHP的 ...

  10. 有关对字符串的处理,需要用到List时的简化写法

    这是项目中的需要根据ComputerName来获取IP的一个方法,如果出现多个ComputerName,需要将多个ComputerName的字符串以“:”分开,传进方法中,然后再处理不同的Name,然 ...