hdu 5437(Alisha’s Party)
来源:互联网 发布:大数据风险预警 编辑:程序博客网 时间:2024/05/20 11:26
题目大意:
Alisha邀请他的朋友来参加她的生日 聚会,每个朋友带着一些价值为v的礼物,所有的朋友到聚会的时间不同,因为房门不够大,所以Alisha会选择在第x(题目输入)个朋友到来的时候打开门让一些朋友进来。进来的规则是,礼物价值高的人先进入,礼物价值相同时,先到的人先进入;(注意:Alisha最后会让所有的人进入,不过进入的顺序依旧按照她的规则)
题目分析:
模拟题,优先队列模拟;
#include <cstdio>#include <iostream>#include <queue>#include <vector>#include <algorithm>#include <string>#include <map>using namespace std;int n, m, q;char name[150000 + 500][210];struct Node{ int ord; int val; friend bool operator < (const Node &a, const Node &b){ if(a.val < b.val || (a.val == b.val && a.ord > b.ord)) return true; return false; }}node[150000 + 100];priority_queue<Node> pq;pair<int, int> door[150000 + 100]; //记录大门开的时间,和允许进入的人数;int nv[150000 + 100];void Init(){ while(!pq.empty()) pq.pop();}int main(){ int T; scanf("%d", &T); while(T--){ Init(); scanf("%d%d%d", &n, &m, &q); string s; for(int i = 0; i < n; ++i){ scanf("%s", name[i]); scanf("%d", &node[i].val); node[i].ord = i; } for(int i = 0; i < m; ++i) scanf("%d%d", &door[i].first, &door[i].second); sort(door, door+m); int num = 0; int cnt = 0; for(int i = 0; i < m; ++i){ while(num < door[i].first) pq.push(node[num++]); for(int j = 0; j < door[i].second && !pq.empty(); j++){ //进入的人数不能超过剩余的人数; nv[cnt++] = pq.top().ord; pq.pop(); } } for(int i = door[m-1].first; i < n; ++i) //让剩下的所有人进入; pq.push(node[i]); while(!pq.empty()){ nv[cnt++] = pq.top().ord; pq.pop(); } int x; for(int i = 0; i < q; ++i){ scanf("%d", &x); //查询第几个人; printf("%s", name[nv[x-1]]); if(i != q-1) printf(" "); } printf("\n"); } return 0;}
0 0
- hdu 5437 Alisha’s Party
- hdu 5437 Alisha’s Party
- HDU 5437 Alisha’s Party
- HDU 5437 Alisha’s Party
- HDU-5437 Alisha’s Party
- HDU 5437 Alisha’s Party
- HDU 5437 Alisha’s Party
- hdu 5437(Alisha’s Party)
- HDU 5437 Alisha’s Party
- HDU 5437 Alisha’s Party
- Alisha’s Party HDU
- HDU 5437 Alisha’s Party 优先队列
- hdu 5437 Alisha’s Party 优先队列
- HDU 5437 Alisha’s Party(模拟)
- hdu 5437Alisha’s Party(优先队列)
- hdu 5437 Alisha’s Party (优先队列)
- hdu 5437 Alisha’s Party 优先队列
- [HDU 5437]Alisha’s Party[模拟]
- switch case语句
- 使用onsctl ping显示ons is not running
- 2015年年度总结
- WM_COMMAND 和 WM_NOTIFY 的区别
- Activiti入门教程三(详解流程引擎配置)
- hdu 5437(Alisha’s Party)
- Mybatis 1.动态sql 2.模糊查询
- POJ 1611 The Suspects
- Python 生成器
- iOS开发之即时通讯之Socket(AsyncSocket)
- Java各种排序算法
- hdu5442 Favorite Donut(后缀数组求正逆序中字典序最大的字符串)
- javascript定义对象写法
- noip2008 ISBN号码 (模拟)