题目链接  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. 将SpringBoot默认Json解析框架jackson替换成fastjson

    步骤一:引入依赖<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson< ...

  2. 最近使用Nginx的一点新得

    1.基本的负载配置 Nginx最简单的配置模块如下 upstream name{ server ip:port; server ip:port; } server { listen 80; serve ...

  3. SXCPC2018 nucoj2007 和Mengjiji一起攻克难关

    problem #include <algorithm> #include <iostream> #include <cstdio> using namespace ...

  4. 分布式存储系统可靠性系列五:副本放置算法 & CopySet Replication

    本文来自网易云社区 作者:孙建良 在分布式存储系统 中说明了,在一定情况下,copyset的数量不是越多越好,在恢复时间确定的情况下,找到合适的copyset的数量可以降低数据丢失的概率. 在分布式存 ...

  5. leetcode 【 Add Two Numbers 】 python 实现

    题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...

  6. hnust 懒人多动脑

    问题 F: 懒人得多动脑 时间限制: 1 Sec  内存限制: 128 MB提交: 93  解决: 30[提交][状态][讨论版] 题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每 ...

  7. svm常用核函数

    SVM核函数的选择对于其性能的表现有至关重要的作用,尤其是针对那些线性不可分的数据,因此核函数的选择在SVM算法中就显得至关重要.对于核技巧我们知道,其目的是希望通过将输入空间内线性不可分的数据映射到 ...

  8. 收藏网址 jquery学习

    http://www.zhangxinxu.com/wordpress/2009/08/jquery-%E5%8D%95%E5%87%BB%E6%96%87%E5%AD%97%E6%88%96%E5% ...

  9. 课堂笔记III

  10. Solr linux安装

    1.下载安装(自行官网下载) 2.解压安装包 3.进入解压后的bin目录执行命令: ./solr start 出现如下警告: 根据提示修改solr.in.sh中的SOLR_ULIMIT_CHECKS属 ...