soj 1778. Dull Game
来源:互联网 发布:怎么注册域名网址 编辑:程序博客网 时间:2024/06/11 16:22
题意:
XX和YY玩一个游戏,有N轮。
每一轮执行操作:
XX在盒子里面放入ai个球(编号num,重量wgt)
YY从盒子里面取出bi个最重的球
问最后盒子里面最重的球的编号和重量
已经确定球的编号两两各不相同,球的重量两两各不相同
思路:
优先队列。
注意的地方:
自己定义的结构体用优先队列的时候需要重载大于号和小于号(指的是优先级的大小关系),注意两个const 必须加。
代码:
#include <cstdio>#include <queue>using namespace std;struct Ball{int n, w;Ball() {}Ball(int _n, int _w): n(_n), w(_w) {}bool operator > (const Ball &b) const { return w > b.w; }bool operator < (const Ball &b) const { return w < b.w; }};int t, n, ai, bi, num, wgt;Ball ans;int main(){scanf("%d", &t);while (t --){priority_queue <Ball> Q;scanf("%d", &n);while (n --){scanf("%d %d", &ai, &bi);while (ai --){scanf("%d %d", &num, &wgt);Q.push(Ball(num, wgt));}while (bi --) Q.pop();}ans = Q.top();printf("%d %d\n", ans.n, ans.w);}}
- soj 1778. Dull Game
- SOJ.Dice Game
- SOJ 1052. Candy Sharing Game
- soj
- a dull day
- soj 1814
- SOJ-1012
- SOJ-1013
- SOJ-1015
- SOJ-1016
- SOJ-3327
- soj 3109
- { }soj.1206
- { }soj.2013
- SOJ-Dollars
- soj 1715
- soj 1681
- soj 6099
- 文件内容的三种方法
- 善用临时表---同时查询多张表的存储过程
- 变量初始化2
- 那些码农的故事5-------就业(2)
- shell去掉空格、逐行读文件、断行符转换、md5
- soj 1778. Dull Game
- SQLHelper
- linux时间函数描述-strptime
- MySQL Replication(复制)基本原理
- ARM反汇编学习
- C++将结构体传给lua
- fatal error LNK1103: 调试信息损坏;请重新编译模块
- Nonconstant parameter for a template class
- CKEDITOR使用与配置