这是一道蛮基础的构造题。

- k         +(k - 1)      -(k - 2)

1 + k ,    1 ,         k ,             2,    ...................

\  /        \  /           \  /

k          k-1          k-2

如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2

这样下来,最后一个数字就是一个中间的数字,过程就是不断向中间逼近。

在k + 1后面的数字,只要升序输出就可以了。

构造题还是不太熟练阿 QAQ

贴代码了:

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
using namespace std;
const int INF = 0x3f3f3f3f; int a[]; int main(){
int i, j, k, t, m, n;
while(EOF != scanf("%d%d",&n,&k)){
if(k == ){
for(i = ; i < n; ++i) printf("%d ",i);
printf("%d\n",n);
continue;
} a[] = + k;
for(i = ; i <= k + ; ++i){
if(i % == )
a[i] = a[i - ] - (k - (i - ));
else
a[i] = a[i - ] + (k - (i - ));
}
int cur = ;
for(i = k + ; i <= n; ++i){
a[i] = k + + cur++;
}
for(i = ; i < n; ++i){
printf("%d ",a[i]);
}
printf("%d\n",a[n]);
}
return ;
}

Codeforces 482 - Diverse Permutation 构造题的更多相关文章

  1. codeforces C. Diverse Permutation(构造)

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

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

  3. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

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

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

  5. CodeForces 483C Diverse Permutation

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

  6. codeforces C. Diverse Permutation

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

  7. [Codeforces 482A] Diverse Permutation

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

  8. CodeForces 21C Stripe 2 构造题

    题目链接: 题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #inclu ...

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

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

随机推荐

  1. include file和include virtual的区别

    1.#include file 包含文件的相对路径,#include virtual包含文件的虚拟路径. 2.在同一个虚拟目录内,<!--#include file="file.asp ...

  2. 使用Protel99 SE 拼板的详细图解(新加队列粘贴方法)

    很多网友跟我沟通,提到我上次博文中的protel99se中做拼板图解过于简略,应大家的有求,重新修改了操作图示. 首先打开PCB文档.如图所示:电路板的原点并没有在边上,为了操作方便和规范,先把有点设 ...

  3. Django里面的RequestContext

    c = RequestContext(request, { 'foo': 'bar', }) get_template('about.html').render(c) 当我们定义一个RequestCo ...

  4. MongoDB初探系列之二:认识MongoDB提供的一些经常使用工具

    在初探一中,我们已经能够顺利的将MongoDB在我们自己的机器上跑起来了. 可是在其bin文件夹以下另一些我们不熟知的工具.接下来,将介绍一下各个小工具的用途以及初探一中MongoDB在data文件夹 ...

  5. hql中不能写count(1)能够写count(a.id)

    hql中不能写count(1)能够写count(a.id)里面写详细的属性 String hql="select new com.haiyisoft.vo.entity.cc.repo.Bu ...

  6. 最简单的javascript 竖向菜单

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  7. 实现JQuery_Accordion功能

    1. 添加AJAX引用 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/li ...

  8. MySQL的字段设计

    1.尽量使用数字,因为文本占空间,不利于查询(针对有限种类文本)

  9. Java多线程之synchronized(三)

    在多线程访问同一个对象中的不同的synchronized方法或synchronized代码块的前提下,也就是“对象监控器”为同一个对象的时候,也就是synchronized的锁为同一把锁的时候,调用的 ...

  10. Java创建线程的细节分析

    转载:http://shmilyaw-hotmail-com.iteye.com/blog/1880902 前言 关于线程创建的问题,可以说是老生常谈了.在刚开始学习Thread的时候基本上都会接触到 ...