CF351E Jeff and Permutation
贪心好题
考虑每个对能否最小化贡献和
先不考虑绝对值相同情况
发现,对于a,b假设|a|<|b|,那么有无贡献只和b的正负有关!如果a在b前面,b取负一定有贡献,a在b后面,b取正一定有贡献
所以,每个对划分给绝对值较大的管辖,管辖关系形成DAG,显然管辖之间互不影响!
一个点的贡献最小就是左边和右边绝对值比它小的个数的较小值!
对于绝对值相同的情况,我们发现这样进行赋值之后,绝对值相同的一定可以呈现出一段负之后一段正的情况
https://www.luogu.org/blog/ywycasm/xie-ti-bao-gao-zong-gong-10-xing-dai-ma-di-shen-ti-cf351e
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');} namespace Miracle{
const int N=;
int le[N],ri[N];
int a[N],n;
int main(){
rd(n);
for(reg i=;i<=n;++i) rd(a[i]),a[i]=abs(a[i]);
ll ans=;
for(reg i=;i<=n;++i){
for(reg j=i+;j<=n;++j){
ri[i]+=(a[j]<a[i]);
}
for(reg j=;j<i;++j){
le[i]+=(a[j]<a[i]);
}
ans+=min(ri[i],le[i]);
}
ot(ans);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
*/
逆序对还是考虑统计贡献比较好考虑
发现只和绝对值较大的有关,且没有后效性,所以可以直接贪心
CF351E Jeff and Permutation的更多相关文章
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- Codeforces Round #204 (Div. 2)->D. Jeff and Furik
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- Codeforces 351B Jeff and Furik 概率 | DP
B. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
随机推荐
- c:if标签判断不为空和其他的值判断
今天用<c:if test=""></c:if>标签时 <c:if test="${sl.chc_status==1 }"> ...
- Deserializing/Serializing SOAP Messages in C#
/// <summary> /// Converts a SOAP string to an object /// </summary> /// <typep ...
- 洛谷 P3258 [JLOI2014]松鼠的新家 树链剖分+差分前缀和优化
目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例: 输出样例: 说明 说明 思路 AC代码 优化 优化后AC代码 总结 题面 题目链接 P3258 [JLOI2 ...
- Kubernetes1.4正式发布
Kubernetes1.4正式发布. 昨天刚预测1.4即将正式发布,结果晚上Kubernetes1.4就正式发布了. 先看看Kubernetes发布历史: Kubernetes 1.0 - 2015年 ...
- poj2391 最大流+拆点
题意:F块草坪,上面有n头牛,可以容纳m个牛遮雨.将草坪一份为2,成为二部图. 对于此题,和poj2112很像,只是2112很明显的二部图.这道题就开始敲,但是建图遇到问题,草坪的2个值怎么处理,于是 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十二章:几何着色器(The Geometry Shader)
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十二章:几何着色器(The Geometry Shader) 代码工 ...
- iOS小技巧:用runtime 解决UIButton 重复点击问题
http://www.cocoachina.com/ios/20150911/13260.html 作者:uxyheaven 授权本站转载. 什么是这个问题 我们的按钮是点击一次响应一次, 即使频繁的 ...
- thinkphp5.0 模板包含文件
在index.html里包含layout.html:{include file=“layout”}它这里是以绝对路径查找所包含的文件,默认是view目录下 在这种情况下,要在在index.html里包 ...
- 《mysql必知必会》笔记3(插入、更新、删除、创建删除更新表、视图)
十九:插入数据 1:insert语句用来将行插入数据表中,可以插入完整的行.行的一部分.插入多行.插入某些查询的结果. 2:不指定列名,可以这样插入: insert into customers va ...
- 64位linux源码安装mysql
一:下载mysql http://dev.mysql.com/downloads/mysql/中的Generally Available(GA) Releases标签页,在MySQL Communit ...