地址: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 ;
}

最新文章

  1. Kendall’s tau-b,pearson、spearman三种相关性的区别(有空整理信息检索评价指标)
  2. jQuery-认识JQuery,jQuery选择器
  3. C#下水晶报表打印自定义纸张
  4. java.lang.ClassNotFoundException
  5. Android 近百个项目的源代码
  6. 小白日记12:kali渗透测试之服务扫描(二)-SMB扫描
  7. flipsnap--手机屏幕水平滑动框架
  8. linux逻辑卷管理
  9. How Tomcat works — 三、tomcat启动(2)
  10. 数论细节梳理&amp;模板
  11. UED与UCD
  12. Test Scenarios for sending emails
  13. MySQL压缩包zip安装
  14. redis 持久化策略、aof配置、测试、手动持久化、aof文件体积优化
  15. windows上通过secureCRT和putty创建密钥登录
  16. Jmeter登录接口返回 status415
  17. FreeRTOS - 定时器使用注意
  18. JSP语法学习笔记
  19. request.setCharacterEncoding()对通过method=&quot;GET&quot;输入的参数无效
  20. mysql基础认识1

热门文章

  1. 将spark默认日志log4j替换为logback
  2. 集成学习AdaBoost算法——学习笔记
  3. JAVA增删改查XML文件
  4. XDocument简单入门
  5. 阿里云CentOS6.8云服务器配置安全组规则
  6. Popwindow系列
  7. Django学习笔记第八篇--实战练习四--为你的视图函数自定义装饰器
  8. Linuxyum源切换阿里云软件源
  9. Liunx新手入门必看
  10. poj1015 Jury Compromise【背包】