点击打开链接

可能出现的问题:

1.当门外人数不足p人时没有判断队列非空,导致RE。

2.在m次开门之后最后进来到一批人没有入队。

3.给定的开门时间可能是打乱的,需要进行排序。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
struct people
{
char name[203];
int arrive;
int value;
/*
friend bool operator <(people a,people b)
{
if(a.value!=b.value)
return a.value<b.value;
return a.arrive>b.arrive;
}
*/
};
struct cmp
{
bool operator() (const people a,const people b) const
{
if(a.value!=b.value)
return a.value<b.value;
return a.arrive>b.arrive;
}
};
struct door
{
int t;
int p;
};
bool cmp1(door a,door b)
{
return a.t<b.t;
}
people peo[150003];
char n[150003][203];
door a[150003];
priority_queue < people , vector <people> , cmp > s;
/*priority_queue <people> s;*/
int main()
{
int T;
int k,m,q;
int i,j,num,v;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&k,&m,&q);
for(i=1;i<=k;i++)
{
scanf("%s",peo[i].name);
scanf("%d",&peo[i].value);
peo[i].arrive=i;
}
j=num=1;
for(i=1;i<=m;i++)
{
scanf("%d%d",&a[i].t,&a[i].p);
}
sort(a+1,a+m+1,cmp1);//排序
for(i=1;i<=m;i++)
{
for(;j<=a[i].t;j++)
{
s.push(peo[j]);
}
for(v=1;v<=a[i].p&&!s.empty();v++)//非空
{
strcpy(n[num++],(s.top()).name);
s.pop();
}
}
for(;j<=k;j++)//最后一批入队
{
s.push(peo[j]);
}
while(!s.empty())
{
strcpy(n[num++],(s.top()).name);
s.pop();
}
for(i=1;i<=q;i++)
{
scanf("%d",&k);
if(i<q)
printf("%s ",n[k]);
else
printf("%s",n[k]);
}
printf("\n");
}
return 0;
}

HDU5437 Alisha’s Party 优先队列的更多相关文章

  1. HDU5437 Alisha’s Party (优先队列 + 模拟)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

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

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

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

  4. hdu5437 Alisha’s Party

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

  5. Alisha’s Party (HDU5437)优先队列+模拟

    Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...

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

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

  7. HDU 5437 & ICPC 2015 Changchun Alisha's Party(优先队列)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

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

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

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

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

随机推荐

  1. java操作数据库出现(][SQLServer 2000 Driver for JDBC]Error establishing socket.)的问题所在即解决办法

    在进行jdbc直接操作数据库时    : 我们需要对该工程进行一次导包(引入"msbase.jar" "mssqlserver.jar" "msuti ...

  2. 在Linux下安装aws命令行操作

    使用安装包安装 环境: Linux, OS X, or Unix Python 2 version 2.6.5+ or Python 3 version 3.3+ 检查Python版本 $ pytho ...

  3. IE9中Media queries在iframe无效的解决方法

    在css中有5个media querie @media screen and(min-width:0px)and(max-width:319px){ body {background-color:re ...

  4. [转]JavaSE 8—新的时间和日期API

    为什么我们需要一个新的时间日期API Java开发中一直存在一个问题,JDK提供的时间日期API一直对开发者没有提供良好的支持. 比如,已有的的类(如java.util.Date和SimpleDate ...

  5. [整]常用的几种VS编程插件

    通过这些编程插件,你可以方便快捷的完成编程的各项任务,以下分别作下简单介绍,欢迎讨论交流. Visual Assist(强烈推荐)网址:http://www.wholetomato.com/功能:VA ...

  6. PhpStorm WebMatrix xDebug 配置开发环境

    1.首先下载WebMatrix安装程序,下载地址 http://www.microsoft.com/web/webmatrix/  安装步骤 参考:http://www.jb51.net/softjc ...

  7. inoic是什么

    本篇只侧重框架提供的功能和能力的研究,请关注后续实际部署使用体验. 一.inoic是什么? inoic是一个可以使用Web技术以hybird方式开发移动app的前端开源框架. 二.inoic框架特点 ...

  8. 获取css style值

    var obj=document.getElementById("btn");var currentStyle=null;if(obj.currentStyle){ current ...

  9. cmd的xcopy命令

    C#项目的PostEvent里经常会用到xcopy命令,复制目录时容易出错,如下: xcopy sourceDir targetDir,其中的2个目录最后不能有反斜杠"",而目录类 ...

  10. Android计算时间差

    想要写个根据消耗时长来确定开始结束时间的小工具,发现Android处理时间上有点累,可能是我没找到合适的方法吧,先把我的解决办法贴出来,有好的解决方法还希望提醒一下: 1.根据时间字符串获取毫秒数 p ...