Codeforces Round #275(Div. 2)-C. Diverse Permutation
http://codeforces.com/contest/483/problem/C
1 second
256 megabytes
standard input
standard output
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as nthe length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).
Print n integers forming the permutation. If there are multiple answers, print any of them.
3 2
1 3 2
3 1
1 2 3
5 2
1 3 2 4 5
By |x| we denote the absolute value of number x.
解题思路:形如1,n,2,n-1,3,n-2.....这样肯定是最优的,但题目要求你正好有k个不同的,那么可以构造出k-1个不同的之后根据k是否为偶数进行单调输出
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int main(){
6 int i, k, n, left, right;
7 while(scanf("%d %d", &n, &k) != EOF){
8 left = ; right = n;
9 for(i = ; i <= k; i++){
if(i&){
printf("%d ", left++);
}
else{
printf("%d ", right--);
}
}
if(k&){
while(left < right){
printf("%d ", left++);
}
printf("%d\n", left);
}
else{
while(left < right){
printf("%d ", right--);
}
printf("%d\n", right);
}
}
return ;
31 }
Codeforces Round #275(Div. 2)-C. Diverse Permutation的更多相关文章
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 ht ...
- 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- Codeforces Round #275 (Div. 2)
A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...
- Codeforces Round #275 (Div. 2) A,B,C,D
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- [Codeforces Round #275 (Div. 2)]B - Friends and Presents
最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ ...
- (原创)Codeforces Round #550 (Div. 3) A Diverse Strings
A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #275 (Div. 2) C
题目传送门:http://codeforces.com/contest/483/problem/C 题意分析:题目意思没啥好说的. 去搞排列列举必须TLE.那么就想到构造. 1.n.2.n-1.3.n ...
随机推荐
- Maven虐我千百遍,我待Maven如初恋
前言 在如今的互联网项目开发当中,特别是Java领域,可以说Maven随处可见.Maven的仓库管理.依赖管理.继承和聚合等特性为项目的构建提供了一整套完善的解决方案,可以说如果你搞不懂Maven,那 ...
- 洛谷 - P1414 - 又是毕业季II - 因数
https://www.luogu.org/problemnew/show/P1414 以后这种gcd的还是尽可能往分解那里想一下. 先把每个数分解,他的所有因子都会cnt+1. 然后从最大的可能因子 ...
- CF888E Maximum Subsequence(meet in the middle)
给一个数列和m,在数列任选若干个数,使得他们的和对m取模后最大( \(1<=n<=35\) , \(1<=m<=10^{9}\)) 考虑把数列分成两份,两边分别暴力求出所有的可 ...
- [Xcode 实际操作]八、网络与多线程-(1)使用Reachability类库检测网络的连接状态
目录:[Swift]Xcode实际操作 本文将演示如何使用Reachability网络状态检测库,检测设备的网络连接状态. 需要下载一个开源的类库:[ashleymills/Reachability. ...
- SpringBoot整合Memached
一.Memached介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站 ...
- 单片机的C语言中位操作用法2
单片机的C语言中位操作用法 在对单处机进行编程的过程中,对位的操作是经常遇到的.C51对位的操控能力是非常强大 的.从这一点上,就可以看出C不光具有高级语言的灵活性,又有低级语言贴近硬件的特点. 这也 ...
- Log4j2 - 动态生成Appender
功能需求 项目里将User分成了各个区域(domain),这些domain有个标志domainId,现在要求在打印日志的时候,不仅将所有User的日志都打印到日志文件logs/CNTCore.log中 ...
- Hexo搭建博客教程(1) - 安装环境与本地搭建
前言 搭建个人博客一般有两种选择,一个是使用WordPress,但是需要将博客搭建在服务器上,不过搭建好后写文章方便,适合没有程序基础的人使用.另一个是使用Hexo,相对简洁高效,不需要服务器,既可以 ...
- 分布式通信-tcp/ip socket
Socket通讯的过程 Server端Listen(监听)某个端口是否有连接请求,Client端向Server 端发出Connect(连接)请求,Server端向Client端发回Accept(接受) ...
- 【poj1734】Sightseeing trip
Sightseeing trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8520 Accepted: 3200 ...