【题解】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. 向现有mvc程序中加入devexpress report

    Open your ASP.NET MVC project. In the main menu of Visual Studio, click the DEVEXPRESS submenu and s ...

  2. 我眼中的AI

    !!!!本文禁止转载,引用,仅供观看 最初了解人工智能是在我上大二的时候,在看头条的时候经常看到有关人工智能的事情,当时的我和大多数的人一样,感觉人工智能很神奇.当时就整晚整晚的想人工智能会取代人类呀 ...

  3. fauxbar.bak

    {"options": { "almostdone":"0", "backup_searchEngines":" ...

  4. Ubuntu 16.04安装深度的Wine(deepin-wine 1.9.0)

    说明: 1.使用的Wine版本是深度出品(Deepin),已经精简了很多没用的配置,使启动能非常快,占用资源小. 2.提取自QQ和迅雷安装包,如果安装了这个Wine不成功,可能是依赖问题,再试多几次, ...

  5. sqld360

    https://mauro-pagano.com/2017/04/15/sql-monitoring-flamegraph-and-execution-plan-temperature-2-0/ ht ...

  6. smartsvn学习(三) Error validating server certificate for

    Error validating server certificate for 'xxxxxxxxxxxx:443':  - The certificate is not issued by a tr ...

  7. Display LOV (List Of Values) Using Show_Lov In Oracle Forms

    Show_Lov Function is used to display list of values (LOV) in Oracle Forms. It returns TRUE if the us ...

  8. 学习和家庭教育 z

    大家好,我是王宁. 今天能站在这里,纯属偶然. 为什么说偶然呢? 因为,南雅是个人才济济的地方,164班是一个优秀的集体. 个人认为,班级前二十几名的同学,时机适宜,谁考班上第一名都有可能. 妈妈对我 ...

  9. 收藏以下linux查看系统信息的命令

    # uname -a               # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue   # 查看操作系统版本# hostname              ...

  10. 每天一个命令 ls

    默认建立一个目录时初始硬连接数为2若该目录下有几个目录就会再增加几个连接数 ls -li 查看inode信息 ls -al 查看所有文件信息 ls -lR 查看目录下目录下的文件(递归显示目录下的文件 ...