【题解】CF359B Permutation

求一个长度为\(2n\)的序列,满足\(\Sigma |a_{2i}-a_{2i-1}|-|\Sigma a_{2i}-a_{2i-1}|=2k\)

这种带绝对值的题目套路就是把绝对值拆开。看看\(n=2\)时候的情况

\(\left[1,2,3,4\right]\)

\(|2-1|+|4-3|-|2-1+4-3|=0\)

\(swap(1,2) =>\)

\(|1-2|+|4-3|-|1-2+4-3|=2\)

也就是交换一组产生\(2\)的贡献,直接交换\(k\)组就好了。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<bitset>
#include<vector>
#include<map>
#include<ctime>
#include<cstdlib>
#include<set>
#include<bitset>
#include<stack>
#include<list>
#include<cmath>
using namespace std;
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define TMP template<class ccf>
#define lef L,R,l,mid,pos<<1
#define rgt L,R,mid+1,r,pos<<1|1
#define midd register int mid=(l+r)>>1
#define chek if(R<l||r<L)return
#define all 1,n,1
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
typedef long long ll;
TMP inline ccf qr(ccf k){
char c=getchar();
ccf x=0;
int q=1;
while(c<48||c>57)
q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)
x=x*10+c-48,c=getchar();
if(q==-1)
x=-x;
return x;
}
const int maxn=5e4+15;
int data[maxn<<1];
int n,k; int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
n=qr(1);
k=qr(1);
RP(t,1,n*2+1)
data[t]=t;
RP(t,1,k)
swap(data[t<<1],data[(t<<1)-1]);
RP(t,1,n*2-1)
cout<<data[t]<<' ';
cout<<data[n*2];
return 0;
}

【题解】CF359B Permutation的更多相关文章

  1. CF359B Permutation (构造)

    CF359B Permutation \(solution:\) 作为一道构造题,这题也十分符合构造的一些通性----(找到一些规律,然后无脑循环). 构造一个长度为 \(2n\) 的排列 \(a\) ...

  2. CF R 209 div 2 CF359B Permutation 构造

    LINK:Permutation 休闲一下 开了一道构造题. 看起来毫无头绪 其实仔细观察第二个条件 0<=2k<=n. 容易想到当n是奇数的时候 k的范围更小 再手玩一下第一个条件 容易 ...

  3. CF359B Permutation 构造

    正解:构造 解题报告: 这个是传送门! 昂直接讲思路趴?毕竟这种构造题的话除了思路也没什么好说的只要想明白辽还是通常来说难度不大的QwQ 首先提供一个对正解毫无启发的由正解启发而来的想法QAQ 就首先 ...

  4. [LeetCode 题解]: Permutation Sequcence

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode]题解(python):031-Next Permutation

    题目来源 https://leetcode.com/problems/next-permutation/ Implement next permutation, which rearranges nu ...

  6. Lintcode388 Permutation Sequence solution 题解

    [题目描述] Given n and k, return the k-th permutation sequence. Notice:n will be between 1 and 9 inclusi ...

  7. csps-s模拟测试62,63Graph,Permutation,Tree,Game题解

    题面:https://www.cnblogs.com/Juve/articles/11631298.html permutation: 参考:https://www.cnblogs.com/clno1 ...

  8. Tree and Permutation (HDU 6446) 题解

    // 昨天打了一场网络赛,表现特别不好,当然题目难度确实影响了发挥,但还是说明自己太菜了,以后还要多多刷题. 2018 CCPC 网络赛 I - Tree and Permutation 简单说明一下 ...

  9. 【CF1443E】Long Permutation 题解(排列生成模板)

    原题链接 题意简介 给定一个长度为 n 的排列 {1,2,3,...,n} .现有两种操作: 对某个区间 [l,r] 求和 将排列往后推 x 次 (按字典序) 其中 \(n,q \leq 2\time ...

随机推荐

  1. GCJ——Minimum Scalar Product(2008 Round1 AA)

    题意: 给定两组各n个数,可任意调整同一组数之中数字的顺序,求 sum xi*yi i=1..n的最小值. Small: n<=8 abs xy,yi<=1000 Large: n< ...

  2. Java 8 Lambda表达式的使用

    lambda表达式允许你通过表达式来代替功能接口.lambda表达式就和方法一样,它提供了一个正常的参数列表和一个使用这些参数的主体(body,可以是一个表达式或一个代码块). Lambda表达式还增 ...

  3. Linux 安装 Java 运行环境

    方式一 # 简单粗暴流# 我使用的是 ubuntu server 18.04 LTS 版本的系统 不同的系统的命令可能存在差异# 在命令行使用java 回车 发现没有Java的话 下面会提示 安装的方 ...

  4. iOS -- iOS11新特性,如何适配iOS11

    前言 这几天抽空把WWDC的Session看了一些,总结了一些iOS11新的特性,可能对我们的App有影响,需要我们进行适配.本文作为一个总结. 本文内容包括:集成了搜索的大标题栏.横向选项卡栏.Ma ...

  5. centos 7 安装五笔输入法

    centos 7 安装五笔输入法 [a@endv ~]$ yum search wubi 已加载插件:fastestmirror, langpacks Loading mirror speeds fr ...

  6. JAVA Eclipse的Android文件结构是怎么样的

    默认res目录下面存放了界面需要的布局和图片文件,之所以图片分为hdpi,ldpi,mdpi这些,是为了不同的设备准备的(高/中/低分辨率的图片)   Bin目录类似于VS的debug或者releas ...

  7. 【TSQL】空格的比较

    空格比较时 空字符串跟任意长度的半角空格字符串比较,结果都为TRUE ) SET @TRUSTOR = '' IF @TRUSTOR IS NULL BEGIN SELECT 'IS NULL' EN ...

  8. JQuery中$.get(),$.post(),$.ajax(),$.getJSON()的区别

    详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON() 一.$.get(url,[data],[callback]) 说明:url为请求地址,d ...

  9. GEM演唱会

    周六去魔都看邓紫棋演唱会,各位看官可能要问.杭州不是也有嚒.为嘛去魔都-..由于po主是逗比哈哈(- ̄▽ ̄-) 早上睡到自然醒,然后開始做午饭.吃完躺沙发上看电视,看到一点多认为应该要出发了(演唱会7 ...

  10. js学习总结--DOM2兼容处理重复问题

    在解决this问题之后,只需要在每次往自定义属性和事件池当中添加事件的时候进行以下判断就好了,具体代码如下: /* bind:处理DOM2级事件绑定的兼容性问题(绑定方法) @parameter: c ...