CodeForces 483C Diverse Permutation
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Permutationp is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote asn the 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.
Input
The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Sample Input
3 2
1 3 2
3 1
1 2 3
5 2
1 3 2 4 5
Hint
By |x| we denote the absolute value of number x.
#include <stdio.h>
#include <string.h>
int main()
{
int n,k;
int i,j;
int a[];
while(scanf("%d %d",&n,&k)!=EOF)
{
memset(a,,sizeof(a));
int j=k+,num=;
a[]=;
printf("");
while(k)
{
if(num-k> && a[num-k]==)
{
printf(" %d",num-k);
num=num-k;
a[num]=;
}
else
{
printf(" %d",num+k);
num=num+k;
a[num]=;
}
k--;
}
for(i=j;i<=n;i++)
{
printf(" %d",i);
}
printf("\n");
}
return ;
}
CodeForces 483C Diverse Permutation的更多相关文章
- codeforces 483C.Diverse Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...
- codeforces C. Diverse Permutation
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [Codeforces 482A] Diverse Permutation
[题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...
- codeforces C. Diverse Permutation(构造)
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
- 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
http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...
- 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
随机推荐
- [sinatra] Just Do It: Learn Sinatra, Part One Darren Jones
1. Install sinatra gem gem install sinatra --no-ri --no-rdoc 2. Basic App #!/usr/bin/ruby require 's ...
- 【python cookbook】【数据结构与算法】17.从字典中提取子集
问题:想创建一个字典,其本身是另一个字典的子集 解决方案:利用字典推导式(dictionary comprehension)可轻松解决 # example of extracting a subset ...
- React笔记_(2)_react语法1
这一节内容主要以了解为主. 渐渐的体会react的语法和其特性. ① htmlAndJs 混合编写 react和以往的前后台书写方式不一样. 在之前的多个语言中,讲求的是将页面代码和js代码逻辑分开, ...
- Datatables带参重绘
研究了好久,最后发现只需要加上参数("bDestory":true,) 即可实现每次刷新就是新的重绘,而无需调用什么desctory init clear等等函数..
- grd文件结构
- 模拟namenode崩溃,使用secondarynamenode恢复
方法一.使用namespaceID 1.在namenode节点上,将dfs.name.dir指定的目录中(这里是name目录)的内容情况,以此来模拟故障发生. [hadoop@node1 name]$ ...
- 19、文件上传与下载/JavaMail邮件开发
回顾: 一. 监听器 生命周期监听器 ServletRequestListener HttpSessionListener ServletContextListener 属性监听器 ServletRe ...
- 浅谈C#当中的out关键字(转载)+说明
与ref关键字一样,out关键字也是按引用来传递的. 示例演示了out关键字的使用方法,其功能是获取数组中的最大值和最大值的索引 using System; using System.Collecti ...
- php header()函数设置页面Cache缓存
header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格. 手册上,我们对于cache都是写着如何设置,以便让代码 ...
- [团队项目]sprint3 & 团队贡献分。
希望各组认真准备,拿出最好的阵容最好的状态,展示一学期的学习与工作成果. 各组注意完成sprint3的博客,写上团队贡献分. 将演示PPT(如果有)和代码上传到github. 截止日期:2016.6. ...