CF 482A(Diverse Permutation-相邻距离不同数为k的1~n全排列构造)
1 second
256 megabytes
standard input
standard output
Permutation p is an ordered set of integers p1, p2, ..., pn,
consisting of n distinct positive integers not larger than n.
We'll denote asn the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n,
that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has
exactly k distinct elements.
The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).
Print n integers forming the permutation. If there are multiple answers, print any of them.
3 2
1 3 2
3 1
1 2 3
5 2
1 3 2 4 5
By |x| we denote the absolute value of number x.
1 10 2 9 3 8 |7 6 5 4 3 2
不同的。
。
。全为1的
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
#define MAXK (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,k;
int main()
{
// freopen("CF482A.in","r",stdin);
// freopen(".out","w",stdout); cin>>n>>k;k--;
int l=1,r=n,b=1;
while(l<=r)
{ if (b) printf("%d",l++);
else printf("%d",r--);
if (k) b^=1,k--; if (l<=r) putchar(' ');
}
cout<<endl;
return 0;
}
CF 482A(Diverse Permutation-相邻距离不同数为k的1~n全排列构造)的更多相关文章
- [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. 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
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
- 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
Diverse Permutation Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- 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 ...
- C. Diverse Permutation(Codeforces Round #275(div2)
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces C. Diverse Permutation(构造)
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...
随机推荐
- 关于JS中原型链中的prototype与_proto_的个人理解与详细总结
一直认为原型链太过复杂,尤其看过某图后被绕晕了一整子,今天清理硬盘空间(渣电脑),偶然又看到这图,勾起了点回忆,于是索性复习一下原型链相关的内容,表达能力欠缺逻辑混乱别见怪(为了防止新人__(此处指我 ...
- java.sql.SQLException: Io 异常: Got minus one from a read call
博客分类: Oracle Tomcat服务器下的应用连接Oracle时报错,出现以下异常: java.sql.SQLException: Io 异常: Got minus one from a r ...
- js调试方法
参考:1.https://developers.google.com/web/tools/chrome-devtools/javascript/ 2.https://developers.google ...
- iOS:Masonry介绍与使用
Masonry介绍与使用实践:快速上手Autolayout frame----->autoresing------->autoLayout-------->sizeClasses ...
- (转)MFC的GUI窗口使用Console输出函数printf
原文链接 在GUI程序中使用printf函数: #include <io.h> #include <fcntl.h> void InitConsole() { ; FILE* ...
- linux后台启动命令-的原因
linux后台启动命令-的原因 学习了:https://blog.csdn.net/saife/article/details/78276014 学习了:https://www.ibm.com/dev ...
- 乌云主站所有漏洞综合分析&乌云主站漏洞统计
作者:RedFree 最近的工作需要将乌云历史上比较有含金量的漏洞分析出来,顺便对其它的数据进行了下分析:统计往往能说明问题及分析事物的发展规律,所以就有了此文.(漏洞数据抓取自乌云主站,漏洞编号从1 ...
- MPJoystick
using UnityEngine; /** * File: MPJoystick.cs * Author: Chris Danielson of (monkeyprism.com) * // USE ...
- iovec结构体定义及使用 (转)
I/O向量(struct iovec) readv(2)与writev(2)函数都使用一个I/O向量的概念.这是由所包含的文件定义的: #include <sys/uio.h> 头文件定义 ...
- Windows环境下完全手工配置Apache、MySQL和PHP
现在LAMP(Linux.Apache.MySQL.PHP/Perl/Python的简称)已经很流行了.在Windows下也有类似的,比如 WAMP(Apache, MySQL, PHP on Win ...