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 */ /*** ...
随机推荐
- scan design flow(二)
在scan stitch之后,scan synthesis就已经完成, Scan extraction主要用来从scan design中extracing所有的instance,来保证scan cha ...
- 2. 星际争霸之php面向对象(二)
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- Asp.net中后台C#数组与前台Javascript数组交互
摘自:http://blog.csdn.net/a6225301/article/details/20003305 在上一篇<asp.net中javascript与后台c#交互>中实现了前 ...
- sql2005镜像实现
-- =========================================== -- 无论是主体服务器.镜像服务器, 还是见证服务器 -- 除特别说明外,均需要保证下面的操作 ...
- (栈的应用5.2.2)POJ 2106 Boolean Expressions(表达式求值)
/* * POJ_2106.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...
- 操作系统—Systemd
操作系统-Systemd 时间 2016-09-24 22:34:49 运维部落 原文 http://www.178linux.com/48990 主题 systemd Systemd 概述: C ...
- 鸟哥的linux私房菜之vim
vim是vi的进阶版本
- 第一轮复习Servlet day04
* 数据的传送接收:后台通过request发送:req.setAttribute("emps", list); req.getRequestDispatcher("emp ...
- 如何清除DNS缓存,使用cmd命令清理DNS缓存方法
如何清除DNS缓存,使用cmd命令清理DNS缓存方法 有时候电脑突然上不了网,或者存在某些网站打不开的情况,但别的网站又可以打开,解决办法需要清除DNS缓存,那么如何清除DNS缓存呢,最常用的方法就是 ...
- 如何在ecshop订单中显示客户给商家的留言
ecshop后台->订单管理->订单打印 在你想要加入的位置加入 客户给商家的留言:{$order.postscript} ok啦,很简单咯