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.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- Linux C 实现Ping功能的程序.
ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具.ping命令的工作原理是:向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文一模一样地传回给发送者,这 ...
- freebsd
#cd /usr/ports/devel/binutils && make install
- 菜农群课笔记之ICP与ISP----20110412(整理版)
耗时一上午时间对HOT大叔昨晚的群课内容进行温故并整理,现将其上传,若想看直播可到下面链接处下载:http://bbs.21ic.com/icview-229746-1-1.html 成 ...
- 在qt下获取屏幕分辨率
1,在Windows下可以使用 GetSystemMetrics(SM_CXSCREEN);GetSystemMetrics(SM_CYSCREEN) 获取. 2,在Linux下可以使用XDisp ...
- [置顶] WEBSOKET服务器搭建
简单介绍一下tomcat的webSocketAPI使用: 在这里啰嗦几句:[ 很多朋友听说webSocket不知道是什么.知道是什么不知道怎么用,知道怎么用不知道具体实现.其实我当初也是这样. 实际上 ...
- 84. 从视图索引说Notes数据库(下)
作用和代价上文介绍了关系型数据库里的索引.Notes数据库里的索引隐藏在视图概念里(本文的讨论仅仅针对Notes的视图索引,不包括全文索引.).开发者创建的视图仅仅是存放在数据库里的一条设计文档.数据 ...
- SVN使用技巧
安装 下载SVN服务端:VisualSVN Server https://www.visualsvn.com/downloads/ 安装,下一步...(更改地址,Location是安装目录,Repos ...
- gridview的高级使用
后台数据 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...
- android studio使用的各种问题
1.添加权限,没有图形界面.添加权限的位置在<application>节点外,如果在节点内添加会报错的 2.查看logcat:要查看logcat的内容,要点一下设备 3.显示行号:在set ...
- Definitions
Definitions and ODR Definitions are declarations that fully define the entity introduced by the decl ...