[Codeforces 482A] Diverse Permutation
[题目链接]
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的更多相关文章
- CodeForces 483C Diverse Permutation
Diverse Permutation Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- codeforces C. Diverse Permutation
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces 483C.Diverse Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...
- codeforces C. Diverse Permutation(构造)
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- 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 ...
- 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 ...
- 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
随机推荐
- 当执行计划中出现BITMAP CONVERSION TO ROWIDS关键字时,需要注意了。
前言 前些天优化了一些耗费buffers较多的SQL,但系统CPU降低的效果不明显,于是又拉了awr报告,查看了SQL ordered by Gets排名前列的SQL. 分析 SQL代码: selec ...
- vue开发--生成token并保存到本地存储中
首先回顾一下token:token认证是RESTFUL.api的一个很重要的部分,通过token认证和token设置,后端会有一个接口传给前台: http://localhost/yiiserver/ ...
- Spider-Scrapy css选择器提取数据
首先我们来说说css选择器:其实在上面的概述:和scrapy相关的函数就这么三个而已:response.css("css表达式").extract().extract_first( ...
- Linux下汇编语言学习笔记47 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- 有用的 SystemTap 脚本
https://segmentfault.com/a/1190000000680628 https://github.com/posulliv/stap
- apple applessd.sys error
http://bbs.feng.com/read-htm-tid-10242622.html
- Mac使用技巧之Finder的个人收藏
当使Finder的时候,左側会列出来个人收藏,能够非常方便的打开对应的文件夹.那么怎样把自己新建的文件夹也增加到个人收藏呢? 1.默认的个人收藏 2.新建名字为my_ios_demo文件夹,拖动这个文 ...
- yarn-cli 添加
添加依赖包 当你想使用另一个包时,你要先把它添加到依赖列表中.也就是执行 yarn add [package-name] 命令将它安装到你的项目中. 这也将同时更新你的 package.json 和 ...
- MongoDB Helper的简单封装
db.properties #mongodb数据库配置文件 #数据库server所在的ip地址 ip=127.0.0.1 #mongodb服务port号 port=27017 #要连接的库 dbNa ...
- jquery验证插件validate自定义扩展
<script src="${pageContext.request.contextPath}/resources/js/jquery-1.12.0.min.js" type ...