【题解】CF359B Permutation
【题解】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的更多相关文章
- CF359B Permutation (构造)
CF359B Permutation \(solution:\) 作为一道构造题,这题也十分符合构造的一些通性----(找到一些规律,然后无脑循环). 构造一个长度为 \(2n\) 的排列 \(a\) ...
- CF R 209 div 2 CF359B Permutation 构造
LINK:Permutation 休闲一下 开了一道构造题. 看起来毫无头绪 其实仔细观察第二个条件 0<=2k<=n. 容易想到当n是奇数的时候 k的范围更小 再手玩一下第一个条件 容易 ...
- CF359B Permutation 构造
正解:构造 解题报告: 这个是传送门! 昂直接讲思路趴?毕竟这种构造题的话除了思路也没什么好说的只要想明白辽还是通常来说难度不大的QwQ 首先提供一个对正解毫无启发的由正解启发而来的想法QAQ 就首先 ...
- [LeetCode 题解]: Permutation Sequcence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode]题解(python):031-Next Permutation
题目来源 https://leetcode.com/problems/next-permutation/ Implement next permutation, which rearranges nu ...
- Lintcode388 Permutation Sequence solution 题解
[题目描述] Given n and k, return the k-th permutation sequence. Notice:n will be between 1 and 9 inclusi ...
- csps-s模拟测试62,63Graph,Permutation,Tree,Game题解
题面:https://www.cnblogs.com/Juve/articles/11631298.html permutation: 参考:https://www.cnblogs.com/clno1 ...
- Tree and Permutation (HDU 6446) 题解
// 昨天打了一场网络赛,表现特别不好,当然题目难度确实影响了发挥,但还是说明自己太菜了,以后还要多多刷题. 2018 CCPC 网络赛 I - Tree and Permutation 简单说明一下 ...
- 【CF1443E】Long Permutation 题解(排列生成模板)
原题链接 题意简介 给定一个长度为 n 的排列 {1,2,3,...,n} .现有两种操作: 对某个区间 [l,r] 求和 将排列往后推 x 次 (按字典序) 其中 \(n,q \leq 2\time ...
随机推荐
- 2016集训测试赛(十九)Problem C: 无聊的字符串
Solution 傻X题 我的方法是建立后缀后缀树, 然后在DFS序列上直接二分即可. 关键在于如何得到后缀树上每个字符对应的字节点: 我们要在后缀自动机上记录每个点在后缀树上对应的字母. 考虑如何实 ...
- Android性能优化第(一)篇---基本概念
最近打算总结几篇app性能优化方面的东西,毕竟android弄了这么久,万一到哪些转了行,岁月久了就忘记了,纯粹当个人笔记.今个是第一篇---性能优化的基本概念,毛主席说了,让理论先行,理论指导实践. ...
- java集合类型接口和实现类个人总结
转载:http://blog.csdn.net/qingchunbusanchang/article/details/39576749 java的集合是一个比较综合的概念,相关的知识有很多的博客里面做 ...
- Win2003 IIS 安装方法 图文教程
最近水一水 质量不高 见谅 一般大家先安装好win2003系统,图文教程 Win2003 服务器系统安装图文教程要通过控制面板来安装.具体做法为: 1. 进入“控制面板”. 2. 双击“添加或删除程序 ...
- SQLite基本(实例FileOrganizer2013.5.12)
工具用 SQLite Dev 数据类型: 1.NULL:空值. 2.INTEGER:带符号的整型,具体取决有存入数字的范围大小. 3.REAL:浮点数字,存储为8-byte IEEE浮点数. 4. ...
- Ant Problem: failed to create task or type foreach 问题
用eclipse导出android时总是会出现有类没有导出的现象,感觉非常麻烦,就用ant些了脚本.在eclipse中运行脚本没问题.可是在命令行下运行会出现 Problem: failed to c ...
- 【Linux】线程并发拷贝程序
据说大连某211高校的李教授越来越重口.不仅延续要求他所带的每个本科班.都要写一份线程并发拷贝程序的传统,并且还開始规定不能用Java语言写作.导致我之前写的<[Java]线程并发拷贝程序> ...
- html用jquery获取屏幕宽度与滚动条的关系
当内容高度超过屏幕高度时,获取的屏幕宽度不包括滚动条.即使是浮动,也要显式设置高度,才会全屏. 未超过时,获取的宽度包括滚动条.
- PHP通过prepare执行查询取得数据
可以用来防止sql注入 <?php $pdo=new PDO("mysql:host=localhost;dbname=itest", 'root',''); //先构建查询 ...
- 深入理解Java 8 Lambda
- 转载:blog1, blog2 以上两篇博客是对lambda表达式的深入理解,用于后续加深理解. 如下先从零开始理解lambda, 1. 接触lambda表达式是从python,javascrip ...