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. Codeforces Beta Round #13 E. Holes (分块)

    E. Holes time limit per test 1 second memory limit per test 64 megabytes input standard input output ...

  2. 关于 CommonJS AMD CMD UMD

    1. CommonJS CommonJS 原来叫 ServerJS, 是服务器端模块的规范,Node.js采用了这个规范. 根据CommonJS规范,一个单独的文件就是一个模块.加载模块使用requi ...

  3. 【DFS】【枚举】Gym - 101246G - Revolutionary Roads

    给你一张有向图,问你将任意一条边变成双向后,所能得到的最大强连通分量的大小. 缩点之后,预处理can(i,j)表示i能到j. 之后枚举每一条边(u,v),再枚举其他所有点t,如果can(u,t) &a ...

  4. 【KMP模板】POJ3461-Oulipo

    [题意] 找出第一个字符串在第二个字符串中出现次数. [注意点] 一定要先将strlen存下来,而不能每次用每次求,否则会TLE! #include<iostream> #include& ...

  5. jquery 封装的ajax调用

    (function(){    var Ploy = {        Config: {            ajaxUrl: "/ajax/ploy.ashx"        ...

  6. php中NULL、false、0、" "有何区别?

    php中很多还不懂php中0,"",null和false之间的区别,这些区别有时会影响到数据判断的正确性和安全性,给程序的测试运行造成很多麻烦.先看一个例子: <? $str ...

  7. [转] EPSG CODE的含义

    董雨    原文地址 之前一直对WKT.EPSG.SRID不是很理解,总是混淆,今天看了一下,清晰了很多,顺便总结一下,嘿嘿:) EPSG(欧洲石油调查小组):European Petroleum S ...

  8. iOS-Runtime、对象模型、消息转发

    Objective-C只是在C语言层面上加了些关键字和语法.真正让Objective-C如此强大的是它的运行时.它很小但却很强大.它的核心是消息分发. Message 执行一个方法,有些语言.编译器会 ...

  9. Nokitjs 系列-01 - HelloWorld

    一.前言 本篇文章需要读者有一点 Node.js 基础的了解,并且已经安装了 Node.js (node.npm),但并不需要有 Nokit 的知识,本文将简单介绍 Nokitjs 的安装使用,并编写 ...

  10. Gulp新手入门教程

    Gulp 是一个自动化工具,前端开发者可以使用它来处理常见任务: 搭建web服务器 文件保存时自动重载浏览器 使用预处理器如Sass.LESS 优化资源,比如压缩CSS.JavaScript.压缩图片 ...