Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造
Codeforces Round #275 (Div. 1)A. Diverse Permutation
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/482/problem/A
Description
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n 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.
Input
Output
Sample Input
3 2
3 1
5 2
Sample Output
1 3 2
1 2 3
1 3 2 4 5
HINT
By |x| we denote the absolute value of number x.
题意
从1-n的数,让你选择一些数来构造,要求每个相邻的数之间的绝对值之差有k种
题解:
按照1,n,2,n-1,3,n-2……这样子构造k-1组,然后把剩下没有遍历的都输出一下就好了
然后还有一种构造是n,1,2,n-1,3,n-2 这样子构造k-1组
这两种构造方法相差1,分别是对应k为奇数和偶数的情况
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//************************************************************************************** inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int main()
{
int flag[maxn];
int n,k;
int ans=;
cin>>n>>k;
if(k%==)
{
for(int i=;i<k-;i++)
{
if(i%)
{
cout<<ans<<" ";
flag[ans]=;
}
else
{
cout<<n-ans<<" ";
flag[n-ans]=;
ans++;
}
}
}
else
{
for(int i=;i<k-;i++)
{
if(i%==)
{
cout<<ans+<<" ";
flag[ans+]=;
}
else
{
cout<<n-ans<<" ";
flag[n-ans]=;
ans++;
}
}
} for(int i=;i<=n;i++)
{
if(flag[i]==)
cout<<i<<" ";
}
return ; }
Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造的更多相关文章
- 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 ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- Codeforces Round #275 (Div. 2)
A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...
- Codeforces Round #275 (Div. 2) A,B,C,D
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- [Codeforces Round #275 (Div. 2)]B - Friends and Presents
最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ ...
- (原创)Codeforces Round #550 (Div. 3) A Diverse Strings
A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #275 (Div. 2) C
题目传送门:http://codeforces.com/contest/483/problem/C 题意分析:题目意思没啥好说的. 去搞排列列举必须TLE.那么就想到构造. 1.n.2.n-1.3.n ...
随机推荐
- jQuery基本筛选器-表单筛选器-关系筛选器
一.基本筛选器 :first // 第一个 :last // 最后一个 :eq(index)// 索引等于index的那个元素 :even // 匹配所有索引值为偶数的元素,从 0 开始计数 :odd ...
- jumpserver安装教程
centos7系统一步一步安装jumpserver 参照官方文档,查找了百度所有的文档,基本上都是按照官方的文档操作的 官方文档点我-> 安装jumpserver需注意: 1:网络环境要好,有的 ...
- JSP中page,request,session,application四个域对象区别
page page指当前页面.只在一个jsp页面里有效 . page里的变量没法从index.jsp传递到test.jsp,只要页面跳转了,它们就不见了. pageContext 如果把变量放到pag ...
- 缓存数据库-redis安装和配置
一:redis安装 python操作redis分为两部分,一为安装redis程序 二是安装支持python操作redis的模块 1)安装redis redis 官方网站:http://www.redi ...
- java基础18 String字符串和Object类(以及“equals” 和 “==”的解析)
一.String字符串 问:笔试题:new String("abc")创建了几个对象?答:两个对象,一个对象是 位于堆内存,一个对象位于字符串常量池 class Demo17 { ...
- Java与redis交互、Jedis连接池JedisPool
Java与redis交互比较常用的是Jedis. 先导入jar包: commons-pool2-2.3.jar jedis-2.7.0.jar 基本使用: public class RedisTest ...
- AdvStringGrid 滚动条问题
1.默认水平方向 滚动条是 小的 滚动的时候 数据会随着滚动 而 滚动的. 2.默认垂直方向 滚动条是 小的 滚动的时候 数据不会随着滚动 而滚动的.ScrollSynch := True; 垂直方向 ...
- Codeforces 988F Rain and Umbrellas(DP)
题目链接:http://codeforces.com/contest/988/problem/F 题目大意: 有三个整数a,n,m,a是终点坐标,给出n个范围(l,r)表示这块区域下雨,m把伞(p,w ...
- Java工程师知识图谱
一.Java工程师知识图谱(思维导图版) 二.Java工程师知识图谱(图文版) 三.Java工程师知识图谱(文字版) http://note.youdao.com/noteshare?id=615da ...
- appium----【Mac】address already in user 127.0.0.1:4725,端口被占用的查找与kill进程
报错截图示例: 解决方法: Mac: lsof -i tcp:4723 #查看端口号 sudo kill -9 29443 #杀死进程 Windows: netstat -aon|fi ...