The 15th UESTC Programming Contest Preliminary J - Jermutat1on cdoj1567
地址:http://acm.uestc.edu.cn/#/problem/show/1567
题目:
Jermutat1on
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
You are given two numbers nn and kk.
You are required to construct a permutation p1,p2,...,pnp1,p2,...,pn of numbers 1,2,...,n1,2,...,n such that there are exactly kk different numbers in |p1−p2||p1−p2|, |p2−p3||p2−p3|, ..., |pn−1−pn||pn−1−pn|.
Input
Only one line contains two integers nn and kk.
1≤k<n≤1000001≤k<n≤100000.
Output
Print nn integers forming the permutation.
If there are multiple answers, print any of them.
If there are no such permutation, print -1
.
Sample input and output
Sample Input | Sample Output |
---|---|
3 1 |
1 2 3 |
Source
#include<iostream>
using namespace std; int n,k; int gcd(int x,int y)
{
if(y==)
return x;
else
return gcd(y,x%y);
} int main()
{
cin>>n>>k;
if(k>=n)
cout<<-<<endl;
else
{
if(k==)
for(int i=;i<=n;i++)
cout<<i<<' ';
else if(k%)
{
int mid=(k+)/;
cout<<mid<<' ';
for(int i=;i<=k;i++)
{
if(i%)
cout<<(mid+=i)<<' ';
else
cout<<(mid-=i)<<' ';
}
for(int i=mid+;i<=n;i++)
cout<<i<<' ';
}
else
{
int mid=k/+;
cout<<mid<<' ';
for(int i=;i<=k;i++)
{
if(i%)
cout<<(mid-=i)<<' ';
else
cout<<(mid+=i)<<' ';
}
for(int i=mid+;i<=n;i++)
cout<<i<<' ';
}
}
return ;
}
The 15th UESTC Programming Contest Preliminary J - Jermutat1on cdoj1567的更多相关文章
- The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554
地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others) M ...
- The 15th UESTC Programming Contest Preliminary B - B0n0 Path cdoj1559
地址:http://acm.uestc.edu.cn/#/problem/show/1559 题目: B0n0 Path Time Limit: 1500/500MS (Java/Others) ...
- The 15th UESTC Programming Contest Preliminary K - Kidd1ng Me? cdoj1565
地址:http://acm.uestc.edu.cn/#/problem/show/1565 题目: Kidd1ng Me? Time Limit: 3000/1000MS (Java/Others) ...
- The 15th UESTC Programming Contest Preliminary M - Minimum C0st cdoj1557
地址:http://acm.uestc.edu.cn/#/problem/show/1557 题目: Minimum C0st Time Limit: 3000/1000MS (Java/Others ...
- The 15th UESTC Programming Contest Preliminary G - GC?(X,Y) cdoj1564
地址:http://acm.uestc.edu.cn/#/problem/show/1564 题目: G - GC?(X,Y) Time Limit: 3000/1000MS (Java/Others ...
- The 15th UESTC Programming Contest Preliminary H - Hesty Str1ng cdoj1551
地址:http://acm.uestc.edu.cn/#/problem/show/1551 题目: Hesty Str1ng Time Limit: 3000/1000MS (Java/Others ...
- The 15th UESTC Programming Contest Preliminary D - Destr0y City cdoj1558
地址:http://acm.uestc.edu.cn/#/problem/show/1558 题目: D - Destr0y City Time Limit: 3000/1000MS (Java/Ot ...
- 【set】【可持久化Trie】The 16th UESTC Programming Contest Preliminary K - Will the circle be broken
题意:You are given an array A of N non-negative integers and an integer M. Find the number of pair(i,j ...
- 【字符串哈希】The 16th UESTC Programming Contest Preliminary F - Zero One Problem
题意:给你一个零一矩阵,q次询问,每次给你两个长宽相同的子矩阵,问你它们是恰好有一位不同,还是完全相同,还是有多于一位不同. 对每行分别哈希,先一行一行地尝试匹配,如果恰好发现有一行无法对应,再对那一 ...
随机推荐
- RabbitMQ之Queues-5
工作队列的主要任务是:避免立刻执行资源密集型任务,然后必须等待其完成.相反地,我们进行任务调度:我们把任务封装为消息发送给队列.工作进行在后台运行并不断的从队列中取出任务然后执行.当你运行了多个工作进 ...
- 编程之美 海量数据寻找 K 大数
1. 使用最小堆, 设置最小堆的大小为K, 仅需遍历一遍即可 2. 寻找最大的 K 个数实质上是寻找第 K 大的数. 通过二分法在区间内不断校正 mid 的值来找到 pivot, 时间复杂度为 o(N ...
- C语言数组元素的查询
在实际开发中,经常需要查询数组中的元素.例如,学校为每位同学分配了一个唯一的编号,现在有一个数组,保存了实验班所有同学的编号信息,如果有家长想知道他的孩子是否进入了实验班,只要提供孩子的编号就可以,如 ...
- jquery 判断ul下是否存在li
$("ul").has("li").length > 0;$("ul > li").length > 0;$(" ...
- Spring源码从开始到放弃(一)
参考<Spring技术内幕>分析. github上面有spring的源码(https://github.com/spring-projects/spring-framework) spri ...
- HighCharts使用心得(转载)
转载自:http://www.cnblogs.com/Olive116/p/3777021.html 1. 准备工作------下载HighCharts插件 跟ECharts一样,HighChart ...
- 160304-01、mysql数据库插入速度和读取速度的调整记录
需求:由于项目变态,需要在一个比较短时间段急剧增加数据库记录(两三天内,由于0增加至5亿).在整个过程调优过程非常艰辛 思路: (1)提高数据库插入性能中心思想:尽量将数据一次性写入到Data Fil ...
- 160519、Oracle中将查询出的多条记录的某个字段拼接成一个字符串的方法
with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Sh ...
- myeclipse 代码提示(alt+/)
windows -->preference-->general-->keys找到 alt+/ 解除绑定 windows -->preference-->general-- ...
- linux, sysrq,acpi,apci,uio,subsystem daemon
linux, sysrq,acpi,apci Linux设备模型 一.sysfs文件系统: sysfs文件系统是Linux2.6内核引入的,它被看成是与proc.devfs和devpty等同类别的文 ...