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 ...
随机推荐
- linux系统 (实验一)实验楼的课程笔记
实验楼的课程笔记 tab 键是命令补全 输入 tail find / 立刻卡住 这时候ctrl+c 可以终端当前指令 一些常用的指令 Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂停当前程序 ...
- thinkphp5.1学习总结
1.修改应用根目录名称 (1)重新定义入口文件如下namespace think; // 定义应用目录define('APP_PATH', __DIR__ . '/../app/'); // 加载基础 ...
- 2019-2-16-WPF-封装-dotnet-remoting-调用其他进程
title author date CreateTime categories WPF 封装 dotnet remoting 调用其他进程 lindexi 2019-02-16 09:40:26 +0 ...
- Leetcode892.Surface Area of 3D Shapes三维形体的表面积
在 N * N 的网格上,我们放置一些 1 * 1 * 1 的立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在单元格 (i, j) 上. 返回结果形体的总表面积. 示例 1: ...
- Wireshark 基本使用方法
学习于: http://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html
- svn upgrade
在我们把我们服务器上的svn 版本号升级以后,我们之前的代码再执行svn命令时,会提示需要执行svn upgrade命令把当前的代码由低版本的svn 上迁移到高版本的svn 上去. 直接执行svn u ...
- .net WebServer示例及调用(接口WSDL动态调用 JAVA)
新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- day39 10-Spring的AOP:基于AspectJ的切点定义
切点是我们真正应用在哪些方法上,增强的那些方法上,就是add().update()和find().delete()是没用的.没用的话就是这三个方法.为什么要定义一个切点呢? 所以可以直接在切面中定义一 ...
- oracle-600错误
event='10841 trace name context forever' 可以屏蔽这个ORA-00600错误. SQL> show parameter event NAME TYPE V ...
- MySQL中使用LIMIT进行分页的方法
一.分页需求: 客户端通过传递start(页码),pageSize(每页显示的条数)两个参数去分页查询数据库表中的数据,那我们知道MySql数据库提供了分页的函数limit m,n,但是该函数的用法和 ...