优先队列 HDOJ 5437 Alisha's Party
题意:一人过生日,很多人排着队送礼物。排队顺序是礼物价值大的优先,如果相等先来的优先。有m次开门,当t个人到了会开门让p个人进门。最后一次让门外的所有人按顺序进门。有q次询问,问第x个进门的人的名字。
分析:很明显的优先队列,首先交给队友做,结果写的搓,无限RE。没办法只能我上,因为要对字符串处理我用了string,思路正确,各种坑都解决了但是很快WA了,我的内心是奔溃的
。赛后发现是cin,cout和scanf,printf冲突了 (ios::sync_with_stdio (false);关闭同步)
,以前听说过这个问题,这次终于碰上了!解题思路是先排好序,t也是要排序的,而且有相同的t,没到t个人来,那么入队t个人,注意队列中不一定有p个人,及时break,详细见代码。
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
using namespace std; const int N = 150000 + 10;
const int INF = 0x3f3f3f3f;
struct People {
string name;
int v, id;
People () {}
People (string n, int v, int id) : name (n), v (v), id (id) {}
bool operator < (const People &r) const {
if (v == r.v) return id > r.id;
else return v < r.v;
}
}p[N], ans[N];
struct Op {
int t, p;
bool operator < (const Op &r) const {
if (t == r.t) return p < r.p;
else return t < r.t;
}
}a[N]; int main(void) {
ios::sync_with_stdio (false); //用了这句话,puts都不能用了
int T; cin >> T;
while (T--) {
int n, m, q; cin >> n >> m >> q;
for (int i=1; i<=n; ++i) {
cin >> p[i].name >> p[i].v; p[i].id = i;
}
for (int i=1; i<=m; ++i) {
cin >> a[i].t >> a[i].p;
}
sort (a+1, a+1+m); int tot = 0;
priority_queue<People> Q;
int n1 = 0, n2 = 1;
while (!Q.empty () || n1 <= n) {
while (n2 <= m && n1 == a[n2].t) {
for (int i=1; i<=a[n2].p; ++i) {
if (Q.empty ()) break;
ans[++tot].name = Q.top ().name; Q.pop ();
}
n2++;
}
n1++;
if (n1 > n) break;
Q.push (People (p[n1].name, p[n1].v, p[n1].id));
}
while (!Q.empty ()) {
ans[++tot].name = Q.top ().name; Q.pop ();
}
for (int x, i=1; i<=q; ++i) {
cin >> x;
cout << ans[x].name;
if (i == q) cout << endl;
else cout << " ";
}
} return 0;
}
优先队列 HDOJ 5437 Alisha's Party的更多相关文章
- HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- hdu 5437 Alisha’s Party 优先队列
Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...
- 优先队列 + 模拟 - HDU 5437 Alisha’s Party
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- hdu 5437 Alisha’s Party 模拟 优先队列
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
- 贪心+优先队列 HDOJ 5360 Hiking
题目传送门 /* 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀 ...
- HDU OJ 5437 Alisha’s Party 2015online A
题目:click here 题意: 邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每 ...
- HDU 5437 Alisha’s Party
题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...
- 15年-ICPC长春-网络赛
ID name status one word POJ 5437 Alisha’s Party 赛后AC. 优先队列,模拟.对时间t排序 POJ 5438 Ponds 赛后AC 循环链表 POJ 5 ...
随机推荐
- c++string 输入换行符
string 一次只能输入一行,不含换行符.可以自己添加换行符 和输入行数.例如:#include <iostream>#include <string>using names ...
- 阿里Java编程规范 学习笔记
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- iOS UI控件之间的关系图
- HDU 5651xiaoxin juju needs help
xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- python模拟登陆discuz论坛
#! /usr/bin/env python # -*- coding: utf-8 -*- import urllib2, urllib, cookielib, re, time class Rob ...
- JRE System Library 与Java EE Libraries的区别
JRE System Library是只要做java开发都需要的完整的.标准的库. Java EE5 Libraries只是java三个方向中做java EE所需要的库.如果做Web方面的开发的话就 ...
- hadoop-3.0.0-alpha4启动
全部启动或者全部停止(注意:第一次启动需要先格式,以后就不需要格式了,不能多次格式化) 1.启动 [root@master sbin]# pwd /usr/hadoop/hadoop-3.0.0-al ...
- VC++编译说明
目录 第1章编译步骤 1 第2章编译源文件 2 2.1 编译器 2 2.2 包含头文件 3 2.3 重复包含 6 2.4 预编译头文件 7 2.4.1 创建 ...
- module+standard library.py
#导入模块 import sys sys.path sys.path.append('D:\program files\Python34\PyWorks') #hello.py文件路径 #不用appe ...
- [Selenium] WebDriver 操作文件系统
1)屏幕截图 接口函数是 TakesScreenshot 示例: import java.io.File; import org.apache.commons.io.FileUtils; public ...