HDU 多校对抗赛第二场 1010 Swaps and Inversions
Swaps and Inversions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3588 Accepted Submission(s): 976
Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.
You don't want to pay too much, so you can try to play some tricks before he sees this sequence. You can pay y yuan to swap any two adjacent elements.
What is the minimum amount of money you need to spend?
The definition of inversion in this problem is pair (i,j) which 1≤i<j≤n and ai>aj.
For each test, in the first line, three integers, n,x,y, n represents the length of the sequence.
In the second line, n integers separated by spaces, representing the orginal sequence a.
1≤n,x,y≤100000, numbers in the sequence are in [−109,109]. There're 10 test cases.
1 2 3
3 1 666
3 2 1
题意:每次交换会花费y的费用,有一个逆序对的会花费x的费用,求最小的费用
题解:找出逆序对的个数,然后求出最小费用即可
逆序对的个数可以用归并排序时的交换次数表示
那么我们只需要在归并排序的时候得到交换次数即可
代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e5+;
int a[maxn];
int c[maxn];
long long ans=;
void Msort(int l,int r){
int mid=(l+r)/;
int i,j,tmp;
if(r>l){
Msort(l,mid);
Msort(mid+,r);
tmp=l;
for(i=l,j=mid+;i<=mid&&j<=r; ){
if(a[i]>a[j]){
c[tmp++]=a[j++];
ans+=mid-i+;
}else{
c[tmp++]=a[i++];
}
}
if(i<=mid) for(;i<=mid;) c[tmp++]=a[i++];
if(j<=r) for(;j<=r;) c[tmp++]=a[j++];
for(i=l;i<=r;i++) a[i]=c[i];
}
} int main(){
int n,x,y,t;
while(scanf("%d%d%d",&n,&x,&y) !=EOF){
ans=;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
Msort(,n-);
for(int i)
long long ans1=min(x,y)*ans;
printf("%lld\n",ans1);
}
return ;
}
HDU 多校对抗赛第二场 1010 Swaps and Inversions的更多相关文章
- HDU 多校对抗赛第二场 1004 Game
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu多校第八场 1010(hdu6666) Quailty and CCPC 排序/签到
题意: CCPC前10%能得金牌,给定队伍解题数和罚时,问你有没有一个队伍如果向上取整就金了,四舍五入就银了. 题解: 排序后按题意求解即可. #include<iostream> #in ...
- 2019 HDU 多校赛第二场 HDU 6598 Harmonious Army 构造最小割模型
题意: 有n个士兵,你可以选择让它成为战士还是法师. 有m对关系,u和v 如果同时为战士那么你可以获得a的权值 如果同时为法师,你可以获得c的权值, 如果一个为战士一个是法师,你可以获得b的权值 问你 ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- 2018牛客暑期ACM多校训练营第二场(有坑未填)
第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...
- hdu多校(二) 1004 1007 1010
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu多校第二场 1010 (hdu6600)Just Skip This Problem
题意: 给你一个数x,允许你多次询问yi,然后回答你x xor yi 是否等于yi,询问尽量少的次数以保证能求出xi是几,求出这样询问次数最少的询问方案数. 结果mod1e6+3 题解: 队友赛时很快 ...
随机推荐
- 【Hadoop】配置环境-伪分布式
目录 1.Linux设置静态IP地址 2.修改主机名和映射文件 3.SSH免密码配置 4.Linux系统JDK的安装和配置 5.Hadoop伪分布式配置和测试 1.Linux设置静态IP地址 1.在L ...
- Python爬虫爬取百度翻译之数据提取方法json
工具:Python 3.6.5.PyCharm开发工具.Windows 10 操作系统 说明:本例为实现输入中文翻译为英文的小程序,适合Python爬虫的初学者一起学习,感兴趣的可以做英文翻译为中文的 ...
- Python3爬虫(一)HTTP相关基础
Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.URI.URL.URN.HTTP URI:统一资源标志符 URL:是URI的一个子集 URN:是URI的另一个 ...
- 分支push不上去的问题
还原一下现场,我在自己的项目里面,从master里面checkout的一个分支,当我在我这个分支里面进行 push代码的操作,我突然发现我的代码不能执行push的操作,如图 这个原因是由于远端的仓库没 ...
- 9.Mongodb与python交互
1.与python交互 点击查看官方文档 安装python包 进入虚拟环境 sudo pip install pymongo 或源码安装 python setup.py 引入包pymongo impo ...
- ProxySQL读写分离测试(续)
Preface I've implemented ProxySQL on PXC yesterday but got some errors when configured query ...
- MySQL☞where与like
1.无条件查询语句(查询表中所有数据) select * from 表名 2.查询某些列的数据(指定列) select 列名1,列名2,列名3 from 表名 3.条件查询语句 select 列名1, ...
- Assetbundle2
Assetbundle可以将Prefab封装起来,这是多么方便啊! 而且我也强烈建议大家将Prefab封装成Assetbundle,因为Prefab可以将游戏对象身上带的游戏游戏组件.游戏脚本.材质都 ...
- spring+apache dbcp +oracle 连接池配置以及优化
特此记录 <!-- 数据源配置, 使用应用中的DBCP数据库连接池 --> <bean id="dataSource" class="org.apach ...
- 阿里云DTS VS MySQLdump
云平台的到来,使得越来越多用户的数据库由云下迁到云上.对于这种情况,阿里对此提出两种方案,一种是MySQL自带的MySQLdump,另外一种就是阿里云的DTS. DTS支持异构数据源之间的数据迁移同步 ...