地址: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. Codeforces 417 D. Cunning Gena

    按monitor排序,然后状压DP... . D. Cunning Gena time limit per test 1 second memory limit per test 256 megaby ...

  2. Spring中Adivisor和Aspect的差别(自我理解)

    在AOP中有几个概念: - 方/切 面(Aspect):一个关注点的模块化,这个关注点实现可能另外横切多个对象.事务管理是J2EE应用中一个非常好的横切关注点样例. 方面用Spring的Advisor ...

  3. Effective C++ Item 10,11 Have assignment operators return a reference to *this Handle assignment to self in operator =

    If you want to concatenate assignment like this int x, y, z; x = y = z = 15; The convention is to ma ...

  4. C++中的自动存储、静态存储和动态存储

    根据用于分配内存的方法,C++中有3中管理数据内存的方式:自动存储.静态存储和动态存储(有时也叫做自由存储空间或堆).在存在是间的长短方面,以这三种方式分配的数据对象各不相同.下面简要介绍这三种类型( ...

  5. IOS6.0调用通讯录和之前的差别

    6.通讯录列表获取差异 自iOS6.0后获取通讯录列表需要询问用户,经过用户同意后才可以获取通讯录用户列表.而且ABAddressBookRef的初始化工作也由ABAddressBookCreate函 ...

  6. Netty 服务端创建

    参考:http://blog.csdn.net/suifeng3051/article/details/28861883?utm_source=tuicool&utm_medium=refer ...

  7. [ Office 365 开发系列 ] 前言

    前言 本人从接触Microsoft SharePoint Server 2007到目前为止,已经在微软SharePoint的路上已经走了好几年,基于SharePoint平台的特殊性,对微软产品线都有了 ...

  8. Python全栈day20(解压序列)

    补充:解压序列 需求一,不通过索引取一个列表的第一个元素和最后一个元素 需求二,交换两个变量的值 L=[1,2,3,4,5,6,7,8,9] #把列表第一个元素赋值给a,最后一个元素赋值给c #中间的 ...

  9. 使用pinyin4j实现汉字转拼音

    1. maven项目,请在pom.xml里边添加包依赖相关配置: <dependency> <groupId>net.sourceforge.pinyin4j</grou ...

  10. cmd运行php

    w D:\wamp64\bin\php\php7.0.4\php.exe  执行了 D:\wamp64\bin\php\php7.0.4\wtest.php