HDU 5437(结构体重载、STL的应用模拟题)
来源:互联网 发布:python base64 key 编辑:程序博客网 时间:2024/06/05 02:52
转自:http://www.cnblogs.com/Apro/p/4807471.html
题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来的人的名字。
特别注意: m可以为0
代码:
#include<stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<math.h>#include<limits.h>#include<time.h>#include<stdlib.h>#include<map>#include<queue>#include<set>#include<stack>#include<vector>#define LL long longusing namespace std;struct node{ int id, val; char name[205]; bool operator < (const node &tmp) const { if(val == tmp.val) return id < tmp.id; return val > tmp.val; }}p[150005];struct opendoor{ int a, b; bool operator < (const opendoor &tmp) const { return a < tmp.a; }}od[150005];set <node> s;int query[105];int main(){ int T; while(~scanf("%d", &T)) { while(T--) { s.clear(); int n, m, q; scanf("%d%d%d", &n, &m, &q); for(int i = 1; i <= n; i++) { scanf("%s%d", p[i].name, &p[i].val); p[i].id = i; } for(int i = 0; i < m; i++) scanf("%d%d", &od[i].a, &od[i].b); sort(od, od + m); int maxq; for(int i = 0; i < q; i++) { scanf("%d", &query[i]); maxq = max(maxq, query[i]); } vector <int> ans; int cnt = 0; for(int i = 1; i <= n && ans.size() < maxq; i++) { s.insert(p[i]); while(od[cnt].a == i && cnt < m)//要在这里判一下……因为m为0时就会使用上一个样例的输入……所以初始化一下也是可以的…… { for(int j = 0; j < od[cnt].b && !s.empty() && ans.size() < maxq; j++) { ans.push_back(s.begin() -> id); s.erase(s.begin()); } cnt++; } } while(!s.empty() && ans.size() < maxq) { ans.push_back(s.begin() -> id); s.erase(s.begin()); } for(int i = 0; i < q; i++) { if(i) printf(" "); cout << p[ans[query[i] - 1]].name; } puts(""); } } return 0;}
阅读全文
0 0
- HDU 5437(结构体重载、STL的应用模拟题)
- 简单介绍结构体重载
- 优先队列-结构体重载
- 优先队列结构体重载的二级排序
- 使用STL去除std::vector自定义结构体重复项
- 【STL】list的应用和模拟实现
- 【STL】 list的应用及模拟实现
- 【STL】list的应用模拟实现
- HDU-5437 Alisha’s Party(STL+模拟)
- HDU 4022 Bombing STL 模拟题
- HDU 1238 Substrings 字符串水题,STL String 的应用
- 暑期集训之结构体重载
- hdu 5131 STL的应用+在线查询
- HDU 1027 STL中next_permutation的应用
- c++ 结构体练习 结构体重的char数组指针
- hdu 4941 STL HASH 模拟
- hdu 2072 找单词 很不错的一道题 模拟 and STL 2种做法
- 参考小白书上用c++采用结构体重载的大数类模版
- 2D游戏的战争迷雾实现方式
- freemarker 数字输出中的逗号问题,${temp}为空问题,时间问题(Java中Date)
- Deep Compression阅读理解及Caffe源码修改
- 再看基础OC基础视频
- DLL调用(3):Java JNA调用DLL
- HDU 5437(结构体重载、STL的应用模拟题)
- linux系统编程之文件I/O
- 梦里什么都有(状压DP)
- PYTHON GUI (PyQt5 安装问题解决)
- 2017-12-12 Python selenuim(续)
- 一个大的含有50M个URL的记录,一个小的含有500个URL的记录,找出两个记录里相同的URL。
- vue开发环境搭建以及项目创建
- 竞赛中使用的数据结构——二叉树
- spark_入门(单词统计)