codeforces C. Diverse Permutation(构造)
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个
|p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素!
思路: 保证相邻的两个数的差值的绝对值为单调递减序列.....
如果够k个了,最后将没有访问到的元素直接添加到末尾!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> #define N 100005
using namespace std; int vis[N];
int num[N];
int main(){
int n, k;
scanf("%d%d", &n, &k);
num[] = ;
vis[] = ;
int c = k, i;
for(i=; i<=n; ++i){
if(num[i-]-c > && !vis[num[i-]-c]){
vis[num[i-]-c]=;
num[i] = num[i-]-c;
}
else if(num[i-]+c <= n && !vis[num[i-]+c]){
vis[num[i-]+c]=;
num[i] = num[i-]+c;
}
--c;
if(c < ) break;
}
for(int j=; j<=n; ++j)
if(!vis[j]) num[++i]=j;
printf("%d", num[]);
for(int j=; j<=n; ++j)
printf(" %d", num[j]);
printf("\n");
return ;
}
codeforces C. Diverse Permutation(构造)的更多相关文章
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 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 ...
- 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 482A] Diverse Permutation
[题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
- 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 ...
随机推荐
- Android模拟器配置
// 检查连接设备,为了保证运行正常,只能留一个连接设备 adb devices
- 内存中 OLTP - 常见的工作负荷模式和迁移注意事项(三)
----------------------------我是分割线------------------------------- 本文翻译自微软白皮书<In-Memory OLTP – Comm ...
- TL-WR702N 连接有线路由
2015-12-23日 备忘录: 1. TL-WR702N一定要设置为 route模式,一定选择“动态ip”,而不是“PPPOE” 2.有线路由器 与 TL-WR702N 的IP不能在一个网段: 目 ...
- 使用MFC提供的Http类下载和上传文件
1.下载文件 Download(const CString& strFileURLInServer, //待下载文件的URL const CString & strFileLocalF ...
- Activiti 删除流程定义
package com.mycom.processDefinition; import java.io.InputStream; import java.util.List; import java. ...
- LM-Sensors unable to load driver module
Fix - sort of - for LM-Sensors unable to load driver module In short: In /etc/default/grub set GRUB_ ...
- qq临时会话设置
qq临时会话怎么设置?QQ正常情况下是不被允许临时会话的,需要加为好友才可以,网上一些教程说代码加QQ号可以直接临时与别人临时会话,其实是不准确的,需要对方开通了临时会话才可以使用该功能.下面来看看怎 ...
- 解决Visual Studio 2010/2012的RC4011 warnings
如果在vc10/11工程的rc文件中有以下任意一行代码: #include <winuser.h> #include <richedit.h> 那么vc将会给出一对警告: C: ...
- Linux驱动开发学习笔记(1):LINUX驱动版本的hello world
1.关于目录 /lib/modules/2.6.9-42.ELsmp/build/ 这个是内核源码所在的目录 一般使用这样的命令进入这个目录:cd /lib/modules/$(una ...
- ImageEdit 加载图片
从本地加载图片 <dxe:ImageEdit Name="iePortrait" Height="120" Width="100" S ...