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