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 ...
随机推荐
- VisualTreeHelper使用——使用BFS实现高效率的视觉对象搜索
BFS,即广度优先搜索,是一种典型的图论算法.BFS算法与DFS(深度优先搜索)算法相对应,都是寻找图论中寻路的常用算法,两者的实现各有优点. 其中DFS算法常用递归实现,也就是常见的一条路找到黑再找 ...
- AC自动机fail树小结
建议大家学过AC自动机之后再来看这篇小结 fail树就是讲fail指针看做一条边连成的树形结构 fail指针在AC自动机中的含义是指以x为结尾的后缀在其他模式串中所能匹配的最长前缀的长度 所以在模式串 ...
- phpcms万能字段的使用方法
今天想做一个单选的字段,里面要使用别的字段,于是研究了一下万能字段!刚开始使用的时候,在网上,论坛里找了好久,没发现一个贴子有针对万能字段的使用说明,官方的例子里也只有一个调用字段本身值的变量 {FI ...
- facebook登录深入研究
PHP sdk https://developers.facebook.com/docs/php/gettingstarted javascript对接PHP https://developers.f ...
- XSD 命令及 WSDL 命令
[XSD] 方法一:通过Xsd2Code工具生成相应代码(制作XSD工具有:Altova XMLSpy) 方法二:通过XSD命令生成相应代码 XML 架构定义 (Xsd.exe) 工具从 XDR.XM ...
- Hibernate中的Session对象 标签: hibernatesession 2017-01-22 22:10 238人阅读 评论(
Hibernate中的Session 大家在看hibernate视频的时候一定都发现了,每次要操作数据库,总是要新建一个session对象,Hibernate在对资料库进行操作之前,必须先取得Sess ...
- bzoj1191 超级英雄
Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金.主持人问题准备了若干道题目,只有当选手正确回 ...
- SQLServer —— 用户权限操作
说明 以下操作都是基于SQLServer登陆验证方式登陆.而且操作员都是 sa. 一.添加登陆账号 use master go ' 第一个(xu)是登陆名,第二个(123456)是登陆密码. 执行语句 ...
- TIJ——Chapter Six:Access Control
package:the library unit The levels of access control from "most access" to "least ac ...
- BZOJ 1008 越狱题解
其实这题很水,显然n个房间有m种宗教,总共有n^m种情况, 我们再考虑不合法的情况,显然第一个房间有m种情况,而后一种只有m-1种情况(因为不能相同) 所以不合法的情况有(m-1)^(n-1)*m种情 ...