点击打开链接

可能出现的问题:

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. Linux查看系统信息(操作系统版本,进程,任务,CPU,内存,磁盘等信息)

    查看操作系统: cat /proc/version   # 内核版本 cat /etc/issue   # 发行版本 head -n 1 /etc/issue uname -a lsb_release ...

  2. Android实现Activity页面跳转切换动画特效

    了解Android程序设计的人应该知道,在Android 2.0之后有了overridePendingTransition(),其中里面两个参数,一个是前一个activity的退出,另一个activi ...

  3. ArangoDB介绍——未知架构和底层原理

    ArangoDB介绍 ArangoDB是一个开源NoSQL数据库,官网:https://www.ArangoDB.org/ArangoDB支持灵活的数据模型,比如文档Document.图Graph以及 ...

  4. [转]网络时间的那些事及 ntpq 详解

    Gentoo(也许其他发行版也是?)中 "ntpq -p" 的 man page 只有简短的描述:“打印出该服务器已知的节点列表和它们的状态概要信息.” 我还没见到关于这个命令的说 ...

  5. java入门第二步之helloworld【转】

    前一篇博客已经介绍了jdk的安装:接下来我们就乘热打铁,完成第一个程序:helloworld(每学一样程序的新东西都是从实现helloworld开始的) 1.不是用开发工具IDE,只是使用记事本来实现 ...

  6. 使用@Controller注解为什么要配置<mvc:annotation-driven />

    自己看了官方文档,也到网上查了下,目前理解如下: <mvc:annotation-driven/>相当于注册了DefaultAnnotationHandlerMapping和Annotat ...

  7. drbd

    1.DRBD安装 1.1.安装依赖包: [java] view plaincopy yum -y install gcc kernel-devel kernel-headers flex 下载安装dr ...

  8. PHP慢脚本日志和Mysql的慢查询日志(转)

      1.PHP慢脚本日志 间歇性的502,是后端 PHP-FPM 不可用造成的,间歇性的502一般认为是由于 PHP-FPM 进程重启造成的. 在 PHP-FPM 的子进程数目超过的配置中的数量时候, ...

  9. Linux中如何让命令在后台运行

    1.在下达的命令后面加上&,就可以使该命令在后台进行工作,这样做最大的好处就是不怕被ctrl+c这个中断指令所中断. 2. 那大家可能又要问了,在后台执行的程序怎么使它恢复到前台来运行呢?很简 ...

  10. nginx查看配置文件nginx.conf路径

      当你执行 nginx -t 得时候,nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径:  # nginx -t nginx: the configu ...