C. Diverse Permutation
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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
n 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 test(s)
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note

By |x| we denote the absolute value of number
x.

求n个数的序列,相邻两个数的绝对值的不同取值有k个 但详细哪k个数不限

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 100009
using namespace std;
int a[N];
int vis[N]; int main()
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
int t=n;
int m=1; for(int i=1;i<=k;i+=2)
{
a[i]=m;
m++;
}
for(int i=2;i<=k;i+=2)
{
a[i]=t;
t--;
} if(k%2==0)
{
for(int i=k+1;i<=n;i++)
a[i]=a[i-1]-1;
}
else
for(int i=k+1;i<=n;i++)
a[i]=a[i-1]+1; for(int i=1;i<n;i++)
cout<<a[i]<<" ";
cout<<a[n]<<endl;
}
return 0;
}

codeforces C. Diverse Permutation的更多相关文章

  1. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  2. codeforces 483C.Diverse Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...

  3. [Codeforces 482A] Diverse Permutation

    [题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...

  4. codeforces C. Diverse Permutation(构造)

    题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...

  5. Codeforces 482 - Diverse Permutation 构造题

    这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ....... ...

  6. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  7. 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 ...

  8. 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 ...

  9. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

随机推荐

  1. 洛谷—— P1598 垂直柱状图

    P1598 垂直柱状图 题目描述 写一个程序从输入文件中去读取四行大写字母(全都是大写的,每行不超过72个字符),然后用柱状图输出每个字符在输入文件中出现的次数.严格地按照输出样例来安排你的输出格式. ...

  2. Python开发基础-Day10生成器表达式形式、面向过程编程、内置函数部分

    生成器表达式形式 直接上代码 # yield的表达式形式 def foo(): print('starting') while True: x=yield #默认返回为空,实际上为x=yield No ...

  3. Linux基础系列-Day7

    NFS服务(基于CentOS 7.0) NFS(Network File System),网络文件系统,是linux与linux之间进行文件共享的服务,在NFS应用,本地NFS的客户端可以透明地读写位 ...

  4. [xsy2282]cake

    题意:一个$n\times n$的有标号点阵,现在用一条直线把它们分成两部分,问有多少种不同的分法 结论:方案数就是以点阵上的点为端点且不经过第三个点的线段数 对一个满足要求的线段,将其绕中点顺时针转 ...

  5. 交换x,y的三种方式

    1 值传递: #include<iostream> using namespace std; int main(){ void change(int ,int); int x=2,y=3; ...

  6. Bootstrap-table固定表头并解决表头与内容不对齐

    写在前面: 之前在做表格的时候,一直忽略了表格的height高度,导致表格的的表头不能固定,这个样子当表格数据过多的时候,导致无法分辨表头是什么,所以决定固定表头. 固定表头需要使用height这一属 ...

  7. Codeforces Round #114 (Div. 1) E. Wizards and Bets 高斯消元

    E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some countr ...

  8. MYSQL复习笔记5-select-from-where子句

    Date: 20140125Auth: Jin参考:http://dev.mysql.com/doc/refman/5.1/zh/sql-syntax.html#select一.select子句主要定 ...

  9. Ubuntu 16.04通过NetworkManager(GUI)配置网桥

    说明:配置好网桥之后一定要重启,不然不生效.这个是Desktop版GUI设置的问题.Server版不会. 配置: 参考: http://www.jb51.net/LINUXjishu/333778.h ...

  10. inno setup 脚本常用修改 转

    http://blog.sina.com.cn/s/blog_72c2eb350100y2sa.html 有人提及想更换安装界面的图片,其实方法很简单,只需要修改inno setup安装目录下的Wiz ...