地址:http://acm.uestc.edu.cn/#/problem/show/1567

题目:

Jermutat1on

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

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

The 15th UESTC Programming Contest Preliminary
 思路:水题,见代码。
 #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的更多相关文章

  1. 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 ...

  2. 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)    ...

  3. 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) ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 【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 ...

  9. 【字符串哈希】The 16th UESTC Programming Contest Preliminary F - Zero One Problem

    题意:给你一个零一矩阵,q次询问,每次给你两个长宽相同的子矩阵,问你它们是恰好有一位不同,还是完全相同,还是有多于一位不同. 对每行分别哈希,先一行一行地尝试匹配,如果恰好发现有一行无法对应,再对那一 ...

随机推荐

  1. [转]Oracle dbms_random函数用法快速生成多条测试数据

    Java 随机生成中文姓名,手机号,邮编,住址:http://blog.csdn.net/xiaokui_wingfly/article/details/45913885 Java 批量随机生成身份证 ...

  2. 集成学习AdaBoost算法——学习笔记

    集成学习 个体学习器1 个体学习器2 个体学习器3   ——> 结合模块  ——>输出(更好的) ... 个体学习器n 通常,类似求平均值,比最差的能好一些,但是会比最好的差. 集成可能提 ...

  3. css属性image-redering详解

    What? image-rendering作为现阶段还处于实验性质中的css属性,他的作用是在浏览器对图片进行比例缩放时,设置其缩放使用的算法,从而来得到我们最终想要的图片结果.而且这个属性可以应用于 ...

  4. 小谈js原型链和继承

    原型(prototype)在js中可是担当着举足轻重的作用,原型的实现则是在原型链的基础上,理解原型链的原理后,对原型的使用会更加自如,也能体会到js语言的魅力. 本文章会涉及的内容 原型及原型对象 ...

  5. $_SERVER,IP,域名常用方法

    PHP $_SERVER详解   $_SERVER['HTTP_ACCEPT_LANGUAGE']//浏览器语言 $_SERVER['REMOTE_ADDR'] //当前用户 IP . $_SERVE ...

  6. 模拟http请求 带 chunked解析办法二

    以PHP代码为例 //这个是解析chuned块 get_chunk_data($fsock) { $data = ''; while(true) { $len = hexdec(fgets($fsoc ...

  7. Android得到SD卡文件夹大小以及删除文件夹操作

    float cacheSize = dirSize(new File(Environment.getExternalStorageDirectory() + AppConstants.APP_CACH ...

  8. 170314、工具:apache httpClient多线程并发情况下安全实用及工具类分享

    简单用法介绍:介绍来源网络 建立连接:在HttpClient中使用多线程的一个主要原因是可以一次执行多个方法.在执行期间,每一个方法都使用一个HttpConnection实例.由于在同一时间多个连接只 ...

  9. 不阻塞浏览器的解析,待外部js下载完成后异步执行

    网站统计中的数据收集原理及实现(js埋点实现) - lastwhisper - CSDN博客 https://blog.csdn.net/l1212xiao/article/details/80450 ...

  10. c++ socket相关

    http://blog.sina.com.cn/s/blog_43ad62c70100gtow.html,一个简单的C语言的socket服务器和客户端程序 http://www.cnblogs.com ...