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

- 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. jmeter cookie管理器 使用方法---新手学习记录1

    首先得抓包: 我已post方法为例: POST /api/datasources/lemontest/jaql HTTP/1.1 Host: 192.168.1.107:8081 Content-Le ...

  2. .NET study collection links

    Parameter Binding in ASP.NET Web API http://www.asp.net/web-api/overview/formats-and-model-binding/p ...

  3. 基于MAVEN的SSM+ehcache+c3p0

    目录结构: 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...

  4. 软件包管理_rpm命令管理_yum工具管理_文件归档压缩_源码包管理

    rpm命令管理软件 对于挂载的像U盘那种都会在midea目录下,但是会显示在桌面上 安装软件(i:install,v:verbose冗长的,h:human):rpm  -ivh  xxxx.rpm 安 ...

  5. Struts2学习笔记(二) 使用通配符动态调用方法

    <package name="other" extends="struts-default"> <action name="xxx_ ...

  6. android搭建环境错误 daemon not running. starting it now on port 5037 ADB server didn't ACK

    android搭建环境错误 daemon not running. starting it now on port 5037 ADB server didn't ACK ADB server didn ...

  7. MBTI性格自测

    这两天身边许多朋友都在测一个叫做MBTI的测试,这个测试从动力.信息收集.决策方式.生活方式四个方面评价一个人. 我发现原来在日常的交往中的差异和冲突不是没理由的,也不是别人故意要为难你,而是因为不懂 ...

  8. swt combo 自动补全

    public class AutoCompleteComboMain {     static final Display display = new Display();     static fi ...

  9. 禁用Visual Studio 2013的Browser Link功能

    禁用Visual Studio 2013的Browser Link功能 GET http://localhost:37478/7fd25f8af33f443494e765be19be6240/brow ...

  10. Leetcode解题记录

    尽量抽空刷LeetCode,持续更新 刷题记录在github上面,https://github.com/Zering/LeetCode 2016-09-05 300. Longest Increasi ...