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的更多相关文章

  1. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  2. 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 ...

  3. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  4. 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 ...

  5. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  6. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  7. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  8. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  9. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

随机推荐

  1. Neo4j文档

    Neo4j 图数据库 主要有节点和关系,关系是有向边,节点和关系都有属性,属性是键值对 Neo4j使用CQL语句,代表Cypher查询语言 相当于SQL 统一声明 在所有的语句中均有结构 <no ...

  2. 【风马一族_php】数组函数

    原文来自:http://www.cnblogs.com/sows/p/6045699.html (博客园的)风马一族 侵犯版本,后果自负  2016-11-09 15:56:26 数组 函数 php- ...

  3. 三.BP神经网络

    BP神经网络是包含多个隐含层的网络,具备处理线性不可分问题的能力.以往主要是没有适合多层神经网络的学习算法,,所以神经网络的研究一直处于低迷期. 20世纪80年代中期,Rumelhart,McClel ...

  4. windows下MySQL 5.7.19版本sql_mode=only_full_group_by问题

    用到GROUP BY 语句查询时出现 which is not functionally dependent on columns in GROUP BY clause; this is incomp ...

  5. 递归系列——树型JSON数据转换问题

    JSON数据转换方式: 1.标准结构=>简单结构 var root = { id: 'root', children: [ { id: "1", children: [ { ...

  6. PHP来控制Linux,ssh2来控制服务器端

    注意:我们用PHP来控制Linux,php环境可以在windows也可以在linux,但是我们要控制的机器是一台linux(被控制的linux关闭selinux和firewalld). 如果php在l ...

  7. day39 10-Spring的AOP:基于AspectJ的切点定义

    切点是我们真正应用在哪些方法上,增强的那些方法上,就是add().update()和find().delete()是没用的.没用的话就是这三个方法.为什么要定义一个切点呢? 所以可以直接在切面中定义一 ...

  8. 闲鱼Flutter&FaaS云端一体化架构

    讲师介绍 国有,闲鱼架构团队负责人.在7月13号落幕的2019年Archsummit峰会上就近一年来闲鱼在Flutter&FaaS一体化项目上的探索和实践进行了分享. 传统Native+Web ...

  9. element-ui select 二级联动

    在使用select 选择框时,2个select 怎么关联在一起(第一个值发生变化,第二个select值随第一个变化而不同)  两个输入框代码 <el-form :inline="tru ...

  10. 洛谷3067 BZOJ 2679题解(折半搜索)

    传送门 BZOJ传送门(权限题) 看到n小于20,就可以想到搜索 所有的数要么在集合a中,要么在集合b中,要么都不在 可是3^n复杂度会炸,我们考虑优化 可以利用折半搜索,将前面一半的所有可能情况与后 ...