题目: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的更多相关文章

  1. [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ

    前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...

  2. hdu oj 1285 确定比赛名次

    hdu oj 1285 确定比赛名次 题目: 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. sort(hdu oj 1425)计数排序和快速排序

    Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0 < n,m < 1000000),第二行包含n个各不 ...

  4. hdu 5437 Alisha’s Party 优先队列

    Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...

  5. hdu 5437 Alisha’s Party 模拟 优先队列

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

  6. 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 ...

  7. 优先队列 + 模拟 - HDU 5437 Alisha’s Party

    Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...

  8. HDU 5437 Alisha’s Party (优先队列模拟)

    题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...

  9. HDU 5437 Alisha’s Party

    题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...

随机推荐

  1. cdoj 韩爷的情书 有向图 欧拉路径

    //欧拉回路 解法:首先判断欧拉回路存在性:1.连通 2.没有出度入度相差大于1的点 3.如果有出度入度相差等于1的点那么必须有两个,一个出度大于入度作为起点,一个入度大于出度作为终点. 在确定了起点 ...

  2. 微信获取用户数据后台写法,author2.0认证

    /* 微信授权接口 */ //1.设置路由 router.get('/wechat/userinfo', function(req, res) { var cb = req.query.cb; //设 ...

  3. ADO.NET FOR MySQL帮助类

    using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...

  4. sql存储过程的简单使用

    存储过程(Stored Procedure)是数据库系统中,一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它. 创建 ...

  5. Asp.Net写文本日志

    底层代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespac ...

  6. rownum(转载)

    对于 Oracle 的 rownum 问题,很多资料都说不支持>,>=,=,between...and,只能用以上符号(<.<=.!=),并非说用>,>=,=,be ...

  7. 【转】在Spring中基于JDBC进行数据访问时怎么控制超时

    http://www.myexception.cn/database/1651797.html 在Spring中基于JDBC进行数据访问时如何控制超时 超时分类 超时根据作用域可做如下层级划分: Tr ...

  8. MFC的资源切换AFX_MANAGE_STATE(AfxGetStaticModuleState()

    转载自:http://blog.chinaunix.net/uid-20532101-id-1931929.html 以前写MFC的DLL的时候,总会在自动生成的代码框架里看到提示,需要在每一个输出的 ...

  9. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  10. [翻译]如何用YII写出安全的WEB应用

    前言 虽然本文是基于YII1.1,但其中提到的安全措施适用于多数web项目安全场景,所以翻译此文,跟大家交流.原文地址. 目录 安全基本措施... 2 验证与过滤用户的输入信息... 2 原理... ...