【题解】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 ...
随机推荐
- [BZOJ3212][POJ3468]A Simple Problem with Integers
题目大意: 维护一个长度为$n(n\leq100000)$的数列,支持区间加.区间求和两种操作,操作共$m(m\leq100000)$次. 思路: Splay区间操作. #include<cst ...
- 基于Java实现的选择排序算法
选择排序和冒泡排序同样是基础排序算法,现在也做个学习积累. 简述 选择排序算法较为稳定,基本上都是O(n2)的时间复杂度,规模越小排序越快,不需要占用额外空间.其实选择排序原理很简单,就是在未排序序列 ...
- springboot 2.0.8 跳转jsp页面
springboot项目创建教程 https://blog.csdn.net/q18771811872/article/details/88126835 springboot 2.0跳转 html教程 ...
- shell date获取时间值
使用Shell获取上一个月.星期的时间范围 #!/bin/bash date_today=`date -d '1 day ago' +%Y%m%d` #最近7天 date_befor_7day=` ...
- node.js博客GitHub搭建(hexo)
教程参考官网提供的: https://hexo.io/zh-cn/ 教程: https://hexo.io/zh-cn/docs/ 我的node.js环境: hexo博客全程采用markdown进行编 ...
- hibernate save update merge 区别
1.save save的对象是临时对象,首先将对象写入缓存,使其变为持久对象. save函数底层使用的是Insert语句,因此如果数据库中已经存在相同ID的记录,那么会报错 2.update upda ...
- 简单实现接口自动化测试(基于python+unittest)
简单实现接口自动化测试(基于python+unittest) 简介 本文通过从Postman获取基本的接口测试Code简单的接口测试入手,一步步调整优化接口调用,以及增加基本的结果判断,讲解Pytho ...
- 18. 使用模板【从零开始学Spring Boot】
转:http://blog.csdn.net/linxingliang/article/details/52017098 18.1 使用thymeleaf 整体步骤: (1) 在pom.x ...
- winform程序公布后,client下载报错“您的 Web 浏览器设置不同意执行未签名的应用程序”
如题 在winserver2008服务器上操作会报错.解决的方法: IE→Internet选项→安全→可信网站,加入信任公布的IP地址
- ZF-net
ZF-net 摘要: 1.这篇文章的motivation 是 :CNN性能良好,可是我们不知道它为何性能良好.也不知道它怎么能够被提高? 2.本文介绍了一种新方法实现中间层和分类器的可视化 3.採用消 ...