HDU 5437by cyl优先队列
来源:互联网 发布:战斗妖精雪风小说淘宝 编辑:程序博客网 时间:2024/06/01 23:02
HDU 5437
题意:
有个人要过生日,有k个朋友来拜访,但是他家里实在是有点小,只能依次让朋友进门,有m个特定的时间,每次可以进入p个人,每一个朋友来会带礼物,价值为v。主人还是比较贪心的,他让朋友进入的条件是谁的礼物价值大谁先进,价值相等就按照拜访的顺序进入。
思路:
可以看出是细节题,考察了对优先队列的掌握,问题在于要猜测出题人的思路,或者说是算法不错但是无法AC的时候,多思考是不是在时间、顺序、思路上有问题。
- 坑点在于输入m个开门的时间需要排序。
#include<cstdio>#include<queue>#include<iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn = 150005;struct ss{ int x; //time int y; //value char name[205]; ss() {} ss(int xx,int yy) { x=xx; y=yy; } bool operator<(const ss& b)const { if(y == b.y) { return x > b.x; } return y<b.y; }}s[maxn];struct Ans{ char name[205];}ans[maxn];struct Door{ int t,p;}door[maxn];int k,m,q;bool cmp1(Door a,Door b){ return a.t < b.t;}int main(){// freopen("in.txt","r",stdin); priority_queue<ss>que1; int ncase; scanf("%d",&ncase); while(ncase--) { scanf("%d%d%d",&k,&m,&q); for(int i = 1;i <= k; i++) { scanf("%s %d",s[i].name,&s[i].y); s[i].x = i; } int time = 1; int pos = 0; while(!que1.empty()) { que1.pop(); } for(int i = 1;i <= m; i++) { scanf("%d%d",&door[i].t,&door[i].p); } sort(door+1,door+1+m,cmp1); for(int i = 1;i <= m; i++) { int t = door[i].t; int p = door[i].p; if(time <= t) { for(;time <= t && time <= k; time++) { que1.push(s[time]); } } while(p > 0 && !que1.empty()) { strcpy(ans[++pos].name,que1.top().name); que1.pop(); p--; } } for(;time <= k; time++) { que1.push(s[time]); } while(!que1.empty()) { strcpy(ans[++pos].name,que1.top().name); que1.pop(); } for(int i = 1;i <= q; i++) { int temp; scanf("%d",&temp); if(i == 1) { printf("%s",ans[temp].name); } else printf(" %s",ans[temp].name); } printf("\n"); } return 0;}
阅读全文
0 0
- HDU 5437by cyl优先队列
- HDU 5441并查集 by cyl
- hdu 5437 (优先队列)
- hdu 5437优先队列
- HDU 5437--优先队列模拟
- HDU-5437-模拟-优先队列
- hdu 5437 优先队列 模拟
- Cyl
- 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 优先队列
- hdu 5437 Alisha’s Party(优先队列)
- 模拟 优先队列(hdu 5437)
- HDU-1509 优先队列
- hdu 4006 优先队列
- bzoj3293/1045 [Cqoi2011]分金币/[HAOI2008] 糖果传递 贪心
- 记录如何解决通过vpn链接公司内网,但是上不了外网的问题
- Adobe CC2018最新系列所有软件全家桶 破解版 赢政天下@vposy
- PAT刷题:1037. Magic Coupon (25)
- 树莓派3b 远程桌面使用opencv窗口不能显示(Window system doesn't support OpenGL)
- HDU 5437by cyl优先队列
- Coursera Deep Learning 第四课 卷积神经网络 第四周 编程作业 Face Recognition for the Happy House-v3
- JSP页面中的隐含对象
- PHP 分页(limit)
- 安装oracle出现Could not execute auto check for display colors using command
- 文章标题
- cuda优化
- Nginx配置官方yum源报404
- Codeforce 893C Rumor (dfs)