博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 483C Diverse Permutation
阅读量:6741 次
发布时间:2019-06-25

本文共 1676 字,大约阅读时间需要 5 分钟。

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

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.

1 #include 
2 #include
3 int main() 4 { 5 int n,k; 6 int i,j; 7 int a[100005]; 8 while(scanf("%d %d",&n,&k)!=EOF) 9 {10 memset(a,0,sizeof(a));11 int j=k+2,num=1;12 a[1]=1;13 printf("1");14 while(k)15 {16 if(num-k>0 && a[num-k]==0)17 {18 printf(" %d",num-k);19 num=num-k;20 a[num]=1;21 }22 else23 {24 printf(" %d",num+k);25 num=num+k;26 a[num]=1;27 }28 k--;29 }30 for(i=j;i<=n;i++)31 {32 printf(" %d",i);33 }34 printf("\n");35 } 36 return 0;37 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4771536.html

你可能感兴趣的文章
Visual Studio 11 Beta新特性(一):安装VS11
查看>>
QQ-weiyun(微云)-云储存
查看>>
微信公众帐号开发教程第3篇-开发模式启用及接口配置(转)
查看>>
第 12 章 Other Web Server
查看>>
.NET项目web自动化测试实战——Selenium 2.0
查看>>
[LeetCode] Split Concatenated Strings 分割串联字符串
查看>>
Asp.Net SignalR - 持久连接类
查看>>
11.8. NAT
查看>>
PowerShell调用jira rest api实现jira统计自动化
查看>>
Git 时间,将代码托管到GitHub 上
查看>>
火车票秒杀攻略
查看>>
关于Asp.Net中FileUpload控件属性PostedFile.ContentType的提示
查看>>
Laravel5做权限管理
查看>>
Spring 通过Java代码装配bean
查看>>
架构重构-好文分享
查看>>
使用shell批量生成数据整合式迁移的脚本
查看>>
[20151021]理解dbms_xplan.display_cursor的format参数all.txt
查看>>
Unicode字符编码标准
查看>>
云计算就像是产业链的重新组合
查看>>
第三代北斗芯片发布 2020年北斗计划向全球提供服务
查看>>