HDU OJ 5437 Alisha’s Party 2015online A
题目:click here
题意:
邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进。最后给出q个数,表示要输出第ni个进来的人的名字。
分析:
优先队列问题。注意优先队列的比较函数即出队顺序,
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm> using namespace std;
const int M = ; struct Node { // 保存来客信息
char name[];
int val;
int id;
bool operator < ( const Node x ) const { // 排序注意--在优先队列中的出队顺序
if( val == x.val ) return id > x.id;
return val < x.val;
}
}node[M];
struct Time { // 保存开门信息--要排序--给的数据可能不按顺序
int t, p;
bool operator < ( const Time x ) const { return t < x.t; }
}time[M]; int k, m, q;
char str[M][]; // 答案 void solve() {
scanf("%d%d%d", &k, &m, &q );
for( int i=; i<=k; i++ ) {
scanf("%s %d", node[i].name, &node[i].val );
node[i].id = i;
}
for( int i=; i<m; i++ )
scanf("%d%d", &time[i].t, &time[i].p );
sort( time, time+m ); // 对开门信息排序
priority_queue<Node> Q;
int order = ;
int last = ;
for( int i=; i<m; i++ ) {
int t, p; t = time[i].t; p = time[i].p;
for( int i=last+; i<=t; i++ ) {
Q.push( node[i] );
}
for( int i=; i<p; i++ ) {
if( Q.empty() ) break; // 注意当门外的人数比p小时--队列判空直接结束--否则会RE
Node nd = Q.top(); Q.pop();
order++;
strcpy( str[order], nd.name );
}
last = t;
}
for( int i=last+; i<=k; i++ ) // m次开门后还要开门一次--门外所有人都进门
Q.push( node[i] );
while( !Q.empty() ) {
Node nd = Q.top(); Q.pop();
order++;
strcpy( str[order], nd.name );
}
bool fo = false; // 输出格式
for( int i=; i<=q; i++ ) {
int s; scanf("%d", &s );
if( fo ) printf(" %s", str[s] );
else { printf("%s", str[s] ); fo = true; }
}
printf("\n");
} int main() {
int t; scanf("%d", &t );
while( t-- ) {
solve();
}
return ;
}
HDU OJ 5437 Alisha’s Party 2015online A的更多相关文章
- [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ
前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...
- hdu oj 1285 确定比赛名次
hdu oj 1285 确定比赛名次 题目: 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- sort(hdu oj 1425)计数排序和快速排序
Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0 < n,m < 1000000),第二行包含n个各不 ...
- 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 模拟 优先队列
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- 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 Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
- HDU 5437 Alisha’s Party
题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...
随机推荐
- 当你还在争夺移动支付的时候,我已经统一了IC卡市场
摘要:虽然说今年移动支付行业的发展很快:苹果.Twitter和Facebook等巨头都开始进军这个市场,再加上PayPal.Coin和Square几个“老玩家”的存在,使得今年的移动支付市场热闹非凡. ...
- U盘常见故障及检修
一般U盘故障分为软故障和硬故障,其中以软故障最为常见. 软故障主要是指U盘有坏块,从而导致U盘能被计算机识别,但没有盘符出现,或者有盘符出现,但当打开U盘时却提示要进行格式化,而格式化又不能成功.前 ...
- Spoken English
The Business lunch 9.商务午餐怎样开场?[0731] Is this your first time in shanghai? 10.怎样询问对方的感受?[0801] How do ...
- SSLSocket实现服务端和客户端双向认证的例子
首先创建服务器端私有密钥和公共密钥1, keytool -genkey -alias serverkey -keystore kserver.ks 密码: serverpass2, keytoo ...
- python 格式化日期
#!/usr/bin/env pythonimport sysimport reimport datetime dd = '2014-08-10'da = datetime.datetime.strp ...
- (转)MapReduce 中的两表 join 几种方案简介
1. 概述 在传统数据库(如:MYSQL)中,JOIN操作是非常常见且非常耗时的.而在HADOOP中进行JOIN操作,同样常见且耗时,由于Hadoop的独特设计思想,当进行JOIN操作时,有一些特殊的 ...
- 浅谈Hash函数
什么是hash函数: hash函数也可以翻译成“散列”函数,一般就使用音译“哈希”函数,简单的说哈希函数是对任意长度的输入进行的压缩映射,所谓的压缩映射顾名思义,输出通常来说要比输入短,并且得到的输出 ...
- 关于 android Intent 传对象和对象数组的一些操作
直接开正题,Intent传递值就是平常那些很简单的,接下来介绍传递 对象,和 对象数组 1 .intent 传递自定义的 对象 - 实体类继承 Serializable public class A ...
- tee 解决readonly 文件无法修改
tee 是什么: 老规矩,找男人问.
- delphi R3下 跨进程获取DLL信息 NtQueryInformationProcess
unit APIUnit; { GetProcessModuleHandle API Unit Ring3调用NtQueryInformationProcess实现跨进程获取DLL句柄 } inter ...