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次询问,每次给你两个长宽相同的子矩阵,问你它们是恰好有一位不同,还是完全相同,还是有多于一位不同. 对每行分别哈希,先一行一行地尝试匹配,如果恰好发现有一行无法对应,再对那一 ...
随机推荐
- jQuery实现淡入淡出二级下拉导航菜单的方法
本文实例讲述了jQuery实现淡入淡出二级下拉导航菜单的方法.分享给大家供大家参考.具体如下: 这是一款基于jQuery实现的导航菜单,淡入淡出二级的菜单导航,很经常见到的效果,这里使用的是jquer ...
- hdu 1561(树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1561 思路:dp[u][i]表示以u为根的树选了i个子节点. #include<iostream ...
- 【黑金原创教程】 FPGA那些事儿《概念篇》
简介一本讲述非软硬片上系统的书,另外还是低级建模的使用手册. 目录[黑金原创教程] FPGA那些事儿<概念篇>:File01 - 结构的玩笑[黑金原创教程] FPGA那些事儿<概念篇 ...
- 【BZOJ3881】[Coci2015]Divljak fail树+树链的并
[BZOJ3881][Coci2015]Divljak Description Alice有n个字符串S_1,S_2...S_n,Bob有一个字符串集合T,一开始集合是空的. 接下来会发生q个操作,操 ...
- 使用jquery修改标题$("title").html("标题")应注意的问题
使用jquery修改标题$("title").html("标题")应注意的问题: 如果修改后的标题和原标题一致,jquery会跳过该操作,这种情况再从其他页面回 ...
- 云计算之路-阿里云上:对“黑色n秒”问题的最终猜想——CPU C-states引起的
如果说2013年云计算之路的主题是“踩坑”,那么2014年我们希望云计算之路的主题变成“填坑”——当然填坑是阿里云来完成的,我们只是见证曾经的坑坑洼洼变成平坦大道. 15号(周四)晚上我们发现了SLB ...
- PacificA: Replication in Log-Based Distributed Storage Systems
PacificA: Replication in Log-Based Distributed Storage Systems - Microsoft Research https://www.micr ...
- Flume简介及使用
一.Flume概述 1)官网地址 http://flume.apache.org/ 2)日志采集工具 Flume是一种分布式,可靠且可用的服务,用于有效地收集,聚合和移动大量日志数据.它具有基于流数据 ...
- Wow! Such Doge!---hdu4847(字符串水题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 题意就是求给出的文章中共有多少个doge,不区分大小写直接用strstr做就可以了: #incl ...
- ssh无密码登录设置
为啥要设置ssh无密码登录? 我们先来看一下分布式系统的一键启动流程, 在matser机器上运行脚本,脚本检测有多少slavers,然后通过ssh登录到slavers,进入到相同的目录(或者通过$XX ...