题目链接  Hrbust 2319

首先把二元组排序,$ai$大的排前面,$ai$相同的$bi$大的排前面。

这样的话就满足了Kim的取数顺序,即选每次$ai$最大的。

考虑得坏一些,在$ai$相同的时候每次选$bi$最大的。

我们从第$2$个位置开始考虑,默认选排名为偶数的,并且一个个把取到的$bi$放进优先队列(小根堆)

当位置标号为奇数并且堆顶元素小于当前的$bi$的时候把堆顶元素弹出来并且把这个$bi$放进去。

其意义为放弃前面标号为偶数点$bi$小的,抓这个编号为奇数并且$bi$大的。

根据Kim的贪婪准则他肯定会去选前面被我们放弃的东西,所以可保证我们得到的$bi$和最大。

最后优先队列里面的元素和即为答案。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 1010; struct node{
LL x, y;
friend bool operator < (const node &a, const node &b){
return a.x == b.x ? a.y > b.y : a.x > b.x;
}
} a[N]; priority_queue <LL, vector <LL>, greater<LL> > q; int T;
int n;
LL ans; int main(){ scanf("%d", &T);
while (T--){
scanf("%d", &n);
rep(i, 1, n) scanf("%lld", &a[i].x);
rep(i, 1, n) scanf("%lld", &a[i].y); sort(a + 1, a + n + 1); rep(i, 2, n) if (i % 2 == 0){
q.push(a[i].y);
}
else if (q.top() < a[i].y){
q.pop();
q.push(a[i].y);
} ans = 0;
while (!q.empty()) ans += q.top(), q.pop();
printf("%lld\n", ans);
} return 0;
}

  

Hrbust 2319 Number Game(贪心)的更多相关文章

  1. Codeforces C. Split a Number(贪心大数运算)

    题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...

  2. Codeforces 980E The Number Games 贪心 倍增表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...

  3. hrbust 2080链表 【贪心】

    仔细看题想想就是个贪心题,两个sort就可以解决了 #include<stdio.h> #include<string.h> #include<math.h> #i ...

  4. BZOJ4922 Karp-de-Chant Number(贪心+动态规划)

    首先将每个括号序列转化为三元组(ai,bi,ci),其中ai为左括号-右括号数量,bi为前缀最小左括号-右括号数,ci为序列长度.问题变为在满足Σai=0,bi+Σaj>=0 (j<i)的 ...

  5. Codeforces 980E The Number Games - 贪心 - 树状数组

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定一颗有$n$个点的树,$i$号点的权值是$2^{i}$要求删去$k$个点,使得剩下的点仍然连通,并且总权值和最大,问删去的所有点的编号. ...

  6. Codeforces - 1189B - Number Circle - 贪心

    https://codeforc.es/contest/1189/problem/B 优先考虑最大的元素怎么构造.拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了. a数组还开错 ...

  7. ZOJ Monthly, March 2018

    A. Easy Number Game 贪心将第$i$小的和第$2m-i+1$小的配对即可. #include<cstdio> #include<algorithm> usin ...

  8. [Leetcode 452] 最少需要射出多少支箭Minimum Number of Arrows to Burst Balloons 贪心 重载

    [题目] There are a number of spherical balloons spread in two-dimensional space. For each balloon, pro ...

  9. Codeforce 835B - The number on the board (贪心)

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

随机推荐

  1. hdu 1257最少拦截系统

    最少拦截系统 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的 ...

  2. CCPC_1003

    这个题可以暴力的哟,直接暴力的哟 不用做什么订立的哟 不需要特别判断的哟 去死吧!!!愚蠢的我! #include<bits/stdc++.h> using namespace std; ...

  3. PowerShell批量启动/关闭Azure VM

    备注:以下例子中出现的JohnsonWeb, JohnsonVm均是虚拟机的名称.在运行Powershell脚本之前,请导入您的订阅文件. 根据条件启动/关闭虚拟机,例如根据虚拟机名称,批量启动/关闭 ...

  4. MySQL和PostgreSQL比较

    1.MySQL相对来说比较年轻,首度出现在1994年.它声称自己是最流行的开源数据库.MySQL就是LAMP(用于Web开发的软件包,包括 Linux.Apache及Perl/PHP/Python)中 ...

  5. 【Clone Graph】cpp

    题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

  6. 【Rotate List】cpp

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...

  7. IntelliJ IDEA下maven Spring MVC配置

    1. 导入工程:或者新建Spring web工程,可以参考博客中的Eclipse Spring MVC的方式: 2.配置Tomcat服务器,有两种方式:一是配置maven插件,而是配置本地Tomcat ...

  8. 通过 purge_relay_logs 自动清理relaylog

    使用背景 线上物理备份任务是在从库上进行的,xtrabackup会在备份binlog的时候执行flush logs,relay-log会rotate到新的一个文件号,导致sql thread线程应用完 ...

  9. Java GUI编程4---标签组件JLabel

    Java GUI编程4---标签组件JLabel 2018年06月11日 22:06:58 蓝蓝223 阅读数 12103更多 个人分类: Java书籍摘抄 所属专栏: Java Swing图形界面 ...

  10. 减法要用 signed 型

    今天调试一个程序,因为Feedback是电流采样值,Setpoint是PWM值,这两个不可能是负值.所以以为Setpoint和Feedback这两个变量都可以设置为u16型(unsigned int) ...