Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题。
- 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 构造题的更多相关文章
- codeforces C. Diverse Permutation(构造)
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...
- 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 ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- codeforces 483C.Diverse Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...
- 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 482A] Diverse Permutation
[题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...
- CodeForces 21C Stripe 2 构造题
题目链接: 题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #inclu ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- C语言实现约瑟夫环讨论
[问题描述] 约瑟夫(Joseph)问题的一种描述是:编号为1,2,…,n的n个人按顺时针方向围坐一圈,每人持有一个密码(正整数).一开始任选一个正整数作为报数上限值m,从第一个人开始按顺时针 ...
- AngularJS Factory Service Provider
先看看http://www.cnblogs.com/mbydzyr/p/3460501.html http://www.oschina.net/translate/angularjs-factory- ...
- COB工艺流程及基本要求
工艺流程及基本要求 清洁PCB---滴粘接胶---芯片粘贴---测试---封黑胶加热固化---测试---入库 1.清洁PCB 清洗后的PCB板仍有油污或氧化层等不洁部分用皮擦试帮定位或测试针位对擦拭的 ...
- 今天刚申请成为Uber司机 已经接了5单了....大家有什么想问的吗?
今天刚申请成为Uber司机 已经接了5单了....大家有什么想问的吗? 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机(全国版最新最详细注册流程)/ ...
- 搜狗2015校园招聘javaproject师面经
面试时看到了我的笔试题.真是慘不忍睹啊. . 1. 问回去有没有研究一下笔试题 木有,果断后面悲剧了 2. 解释一下笔试的一道选择题: 下列哪种操作可能带来死锁? A: lock(m1) lock(m ...
- UISegmentedControl(分页控制器) AND UISlider(滑块控制器)
- (void)viewDidLoad { [super viewDidLoad]; UIImageView * animatedImageView = [[UIImageView alloc]ini ...
- Ext JS学习第十七天 事件机制event(二)
此文仅有继续学习笔记: 昨天说了三种邦定事件的方法,今天说一下自定义事件 假设现在又这样的情景一个自定义的事件 没有用到事件处理的场景 母亲问孩子和不饿-> ...
- ASP.NET 操作配置文件
1.配置文件的各种操作 http://www.cnblogs.com/shimeng3344518/archive/2007/04/23/723999.html 2. http://www.jb51. ...
- 在Office Outlook 2013中收发QQ邮件
选择手动配置 选择第三项 点击More Settings,在Outgoing Server 勾选 如下 确认后,按下一步完成配置,此时会弹出对话框进行邮件发送测试.
- iOS推送证书p12转成pem
首先你需要导出p12格式的证书,具体操作请参考如下: 其次你就可以通过在控制台输入如下命令即可转换: openssl pkcs12 -in 你导出的p12证书 -out 你要转换的pem证书 -nod ...