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个进来 ...
随机推荐
- java如何在函数中调用主函数的数组
import javax.swing.JOptionPane; public class Test { /** * @zdz */ public static void main(String[] a ...
- flash跨域策略文件crossdomain.xml
flash在跨域时唯一的限制策略就是crossdomain.xml文件,该文件限制了flash是否可以跨域读写数据以及允许从什么地方跨域读写数据. 位于www.a.com域中的SWF文件要访问www. ...
- 04737_C++程序设计_第8章_多态性和虚函数
例8.1 分析下面程序的输出结果. 例8.2 分别使用指针和引用的display函数. #include <iostream> using namespace std; const dou ...
- 字典 -- 数据结构与算法的javascript描述 第七章
字典 字典是一种以键-值对形式存储数据的数据结构 最基本功能规划 add 添加数据到字典 remove 从字典中移除数据 get 从字典中取出数据 count 统计字典数据量 find 查找数据在字典 ...
- JavaScript之ClassName属性学习
在前面的style属性学习中,知道了通过style属性可以控制元素的样式,从而实现了行为层通过DOM的style属性去干预变现层显示的目地,但是这种就是不好的,而且为了实现通过DOM脚本设置的样式,你 ...
- JavaScript之Ajax
简介:AJax是在2005年被Adaptive Path的Jesse James Garrett发明的,用户概括异步加载页面内容的技术---说通俗点,Ajax就是实现局部页面通过JavaScript与 ...
- C#Base64加密
using System;using System.Collections.Generic;using System.Text;using System.Security.Cryptography;u ...
- js获取当前年月日
function GetDate(){ var now = new Date(); var year = now.getFullYear(); //年var month = now.ge ...
- jQuery的三种$()
参考脚本之家“http://www.jb51.net/article/21660.htm” $号是jQuery“类”的一个别称,$()构造了一个jQuery对象.所以,“$()”可以叫做jQuer ...
- 记hive select distinct 多列 误区一则
当select distinct a,b,c时,只会对a.b.c都起作用,无法达到只顾虑多余的a列: 根据hive官方网站说明:当有表 a b 10 1 10 2 10 3 此时select a,b ...