HDU5437 Alisha’s Party 优先队列
可能出现的问题:
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 优先队列的更多相关文章
- HDU5437 Alisha’s Party (优先队列 + 模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 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 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...
- hdu5437 Alisha’s Party
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- Alisha’s Party (HDU5437)优先队列+模拟
Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...
- 优先队列 + 模拟 - HDU 5437 Alisha’s Party
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- 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) ...
- 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 (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
随机推荐
- Java--常用类summary(二)
/* 1:StringBuffer(掌握) (1)用字符串做拼接,比较耗时并且也耗内存,而这种拼接操作又是比较常见的,为了解决这个问题,Java就提供了 一个字符串缓冲区类.StringBuffer供 ...
- git 将本地项目添加到远程
git init git add README.md git commit -m "first commit" git remote add origin git@github.c ...
- mrg_myIsam分表引擎用法
CREATE TABLE `test`.`article_0` ( `id` BIGINT( 20 ) NOT NULL , `subject` VARCHAR( 200 ) NOT NULL , ` ...
- 动态链接库dll键盘钩子后台记录代码示例
//.header #ifndef _DLLHOOK_H_ #define _DLLHOOK_H_ #include <windows.h> #define DLL_EXPORT_FUN ...
- bzoj 2244: [SDOI2011]拦截导弹
#include<cstdio> #include<iostream> #include<algorithm> #define M 100009 using nam ...
- Flexbox
使用 Flexbox 的牛逼布局 .container { display: -webkit-flex; display: flex; } .initial { -webkit-flex: initi ...
- [转载]Android 异步加载解决方案
2013-12-25 11:15:47 Android 异步加载解决方案,转载自: http://www.open-open.com/lib/view/open1345017746897.html 请 ...
- 【NOIP2015】提高组D1 解题报告
P1978神奇的幻方 Accepted 描述 幻方是一种很神奇的 N ∗ N 矩阵:它由数字 1,2,3, … … , N ∗ N 构成,且每行.每列及两条对角线上的数字之和都相同. 当 N 为奇数时 ...
- nbtstat -a <IP> 会显示主机名、所在工作组等信息
nbtstat -a <IP> 会显示主机名.所在工作组等信息
- MSP430x1_4_6x之问题总结
01:MSP430端口上电复位的初始值是不确定的:所以使用是都要初始化:比如加下面的语句或者加你使用的端口就行了: /*下面六行程序关闭所有的IO口*/ P1DIR = 0XFF;P1OUT ...