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. 洛谷P1929 迷之阶梯

    P1929 迷之阶梯 题目描述 在经过地球防卫小队的数学家连续多日的工作后,外星人发的密码终于得以破解.它 告诉我们在地球某一处的古老遗迹中,存在有对抗这次灾难的秘密武器.防卫小队立即赶 到这处遗迹. ...

  2. PLAY2.6-SCALA(十二) 表单的处理

    一.表单处理流程如下 1.定义一个表单,在这里表单最多有22个字段 import play.api.data._ import play.api.data.Forms._ //要使用验证和约束 imp ...

  3. scorllview嵌套gridview和listview的兼容问题

    ScrollView嵌套GridView或ListView,由于这两款控件都自带滚动条,当他们碰到一起的时候便会出问题,即GridView会显示不全. 解决办法:自定义一个GridView控件 pac ...

  4. eclipse忽略js文件报错

    eclipse中js文件报错的情况,或许大家早已习以为常了,那么有什么好的方法可以将其忽略掉呢?如果你也在寻找此问题,那么本文或许可以帮助到你忽略某个js文件报错的方法: Project Proper ...

  5. Directx教程(23) 简单的光照模型(2)

    原文:Directx教程(23) 简单的光照模型(2)    在工程myTutorialD3D11_16中,我在文件light.vs中定义了一个材质光源属性常量缓冲. //const buffer最好 ...

  6. oracle审计实施

    1.语句审计 Audit session;  Audit session By ; 与instance连接的每个会话生成一条审计记录.审计记录将在连接时期插入并且在断开连接时期进行更新. 保留有关会话 ...

  7. 洛谷P2607 骑士

    题目描述 Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战火绵延五百里, ...

  8. MUI - 基于plus.downloader的图片懒加载功能,支持本地缓存

    基于plus.downloader的图片懒加载功能,支持本地缓存 简单说一下 在app中,对一些变动不频繁的图片数据(如个人头像等),是需要存储在本地的.我相信这对大多数的app都是强需求的. 怎么使 ...

  9. docker-compose进入容器出现unable to find user root: no matching entries in passwd file

    解决办法: 先docker-compose stop 容器,再docker-compose start 容器.虽然这样可以很快 解决问题,但并非长久之计.

  10. laravel 博客项目部署到Linux系统后报错 权限都设置为777,仍然报错没有权限

    阿里工程师最后给出解决方案.