题目链接  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. Codeforces Round #459 (Div. 2):B. Radio Station

    B. Radio Station time limit per test2 seconds memory limit per test256 megabytes Problem Dsecription ...

  2. 从头开始学习数据库及ADO.NET——竹子整理

    目前为止,学习编程一年有余,写过管理系统,写过商城,写过桌面,接触的多了,乱七八糟的点太多,一堆前段框架,后台类库,纷纷杂杂,更新迭代之快也是令人咋舌.于是我就在想,作为一名程序员,哪些内容是实打实的 ...

  3. Python操作MySQL数据库(二)

    pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同. 下载安装: pip install pymysql 1.执行SQL语句 #!/usr/bin/env pytho ...

  4. fetch 使用记录

    fetch api出来很多年了 ,由于兼容性问题之前一直没在项目中用到,最近做的项目只需兼容IE9+,把fetch引入了进来.目前用起来感觉挺好的,简洁. fetch 返回值是promise对象,对于 ...

  5. 高亮T4模板

    http://t4-editor.tangible-engineering.com/Download_T4Editor_Plus_ModelingTools.html

  6. 【Swap Nodes in Pairs】cpp

    题目: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1-> ...

  7. JWT实现token的生成和认证demo

    上篇写到对JWT的理解,这篇写一个小的demo来实践下 Github:https://github.com/wuhen152033/token/tree/dev 简介 本次的demo是基于Spring ...

  8. c++ primer 6 练习题 (非复习题)

    第7章 7.13-1调和平均数 //7.13-1 excise.cpp 调和平均数 #include <iostream> double calculate(double a,double ...

  9. 使用CORS解决flask前端页面跨域问题

    from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app) @app.route(" ...

  10. 浅谈JavaScript中的函数问题

    前面的话:JavaScript可运行在所有主要平台的主流浏览器上,也可运行在每一个主流操作系统的服务器端上.所以呢,要想成为一名优秀的全栈工程师,必须懂得JavaScript语言.这是我整理的JS的部 ...