http://codeforces.com/contest/351/problem/E

题意:

给出一些数,可以改变任意数的正负,使序列的逆序对数量最少

因为可以任意加负号,所以可以先把所有数看作正数

序列中的数无论怎么改,都不会改变与绝对值最大的数的逆序对的数量

所以从绝对值最大的数开始,决定它的正负

若这个序列中没有重复的最大值

若i是正数,与右边比他小的形成逆序对

若i是负数,与左边比他小的形成逆序对

所以两边取较小的

若序列中出现重复的最大值

那么最优解的最大值一定是 先是若干个负数,然后若干个正数

仍然符合上面的算法

#include<cstdio>
#include<algorithm> using namespace std; int a[]; int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;++i)
{
scanf("%d",&a[i]);
if(a[i]<) a[i]=-a[i];
}
int ans=;
int l,r;
for(int i=;i<=n;++i)
{
l=r=;
for(int j=;j<i;++j)
if(a[i]>a[j]) l++;
for(int j=i+;j<=n;++j)
if(a[i]>a[j]) r++;
ans+=min(l,r);
}
printf("%d",ans);
}
E. Jeff and Permutation
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday.

Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequalityai > aj holds.

Jeff can multiply some numbers of the sequence p by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get.

Input

The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.

Output

In a single line print the answer to the problem — the minimum number of inversions Jeff can get.

Examples
input
2
2 1
output
0
input
9
-2 0 -1 0 -1 2 1 0 -1
output
6

CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation的更多相关文章

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

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  2. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

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

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

  4. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  5. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

  6. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  7. CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly

    http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...

  8. CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle

    http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...

  9. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

随机推荐

  1. 10_Java面向对象_第10天(继承、抽象类)_讲义

    今日内容介绍 1.继承 2.抽象类 3.综合案例---员工类系列定义 01继承的概述 *A:继承的概念 *a:继承描述的是事物之间的所属关系,通过继承可以使多种事物之间形成一种关系体系 *b:在Jav ...

  2. qq飞车精灵家园里的背景音乐:Mysterious Town pooka 下载

      一直都觉得Mysterious Town pooka特别好听,但是酷狗音乐和网上直接搜搜不到,于是我直接从源文件中找了出来.虽然是.ogg格式,但是在酷狗音乐里还是可以播放的.貌似是<奥丁领 ...

  3. jmeter 常用内置变量

    1. vars   API:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html vars.get(& ...

  4. vue组件讲解(is属性的用法)

    什么是组件? 在说之前我们先搞清楚什么是组件?这样对我们下边的学习是很有帮助的. 组件(Component)是Vue.js最强大的功能之一.组件可以扩展HTML元素,封装可以重复使用的代码.在较高层次 ...

  5. python3.6执行AES加密及解密方法

    python版本:3.6.2 首先安装pycryptodome cmd执行命令:pip install pycryptodome 特别简单,代码如下: #!/usr/bin/python # -*- ...

  6. ES6 常用1

    ( (1)交换变量的值 ) [x, y] = [y, x]; ( (2)从函数返回多个值 // 返回一个数组function example() { return [1, 2, 3]; } var [ ...

  7. C语言中变量名及函数名的命名规则与驼峰命名法

    一.C语言变量名的命名规则:(可以字母,数字,下划线混合使用) 1. 只能以字母或下划线开始:2. 不能以数字开始:3. 一般小写:4. 关键字不允许用(eg:int float=2//error  ...

  8. 利用Eric+Qt Designer编写倒计时时钟

    [前言]前几日通过编写命令行通讯录,掌握了Python的基本语法结构,于是开始向更高水平冲击,利用Eric与Qt Designer 编写一个带界面的小程序.本次实操中也确实遇到了不少问题,通过学习也都 ...

  9. 【题解】洛谷P4707重返现世

    在跨年的晚上玩手机被妈妈骂了赶来写题……呜呜呜……但是A题了还是很开心啦,起码没有把去年的题目留到明年去做ヾ(◍°∇°◍)ノ゙也祝大家2019快乐! 这题显然的 kth min-max 容斥就不说了, ...

  10. 【BZOJ2957】楼房重建(线段树)

    [BZOJ2957]楼房重建(线段树) 题面 BZOJ 题解 对于整个区间维护最大斜率以及只考虑这个区间的答案 考虑如何向上合并. 首先左半段的答案是一定存在的 所以,现在的问题就是右半段能够贡献的答 ...