[题目链接]

https://codeforces.com/contest/482/problem/A

[算法]

首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k

对于i > k + 1,令Ai = i

时间复杂度 : O(N)

[代码]

#include<bits/stdc++.h>
using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
int main()
{ int n , k;
read(n); read(k);
printf("");
int value = k , now = ;
for (int i = ; i <= k; i++)
{
if (i & ) now += value;
else now -= value;
printf(" %d",now);
value--;
}
for (int i = k + ; i <= n; i++) printf(" %d",i);
printf("\n"); return ; }

[Codeforces 482A] Diverse Permutation的更多相关文章

  1. CodeForces 483C Diverse Permutation

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

  2. codeforces C. Diverse Permutation

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

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

  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. 安装Vmware Tools出现错误

    安装Vmware Tools出现: Before you can compile modules, you need to have the following installed... makegc ...

  2. PHP:POST OR GET 请求

    文章来源:http://www.cnblogs.com/hello-tl/p/7685216.html /** * 模拟提交参数,支持https提交 可用于各类api请求 * @param strin ...

  3. xtu summer individual-4 D - Martian Strings

    Martian Strings Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  4. hdu 1075

    #include<stdio.h> #include<string.h> #include<string> #include<iostream> #in ...

  5. Python基础之 一 字典(dict)

    字典:是一种key - value的数据类型.语法:info = { key:value }特性:无序,key必须唯一(所以天生去重) 方法如下:del dict[key]:删除字典指定键len(di ...

  6. hdu3756(三分)

    题意:三维坐标轴,有以原点为圆心,底面在xoy平面上,顶点在z轴上的圆锥,问圆锥的最小体积为多少才能完全覆盖空间里的所有点(n<=10000) 分析: 很容易想到转成二维问题,将其投影到xoz平 ...

  7. mysql配置文件my.ini的修改问题

    修改innodb_buffer_pool_size这个参数一般都没问题,但是修改innodb_log_file_size这个参数如果过大,mysql日志就会提示: Error: log file .\ ...

  8. JSP发送电子邮件

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/sending-email.html: 发送一个简单的电子邮件 给出一个简单的例子,从机器上发送一个简单的 ...

  9. Windows Socket IO 模型

    http://www.cppblog.com/huangwei1024/archive/2010/11/22/134205.html

  10. iText输出中文的三种字体选择方式

    1.使用iTextAsian.jar中的字体    BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",Bas ...