点击打开链接

可能出现的问题:

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. 20145236 《Java程序设计》第7周学习总结

    20145236 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 认识时间与日期 时间的度量 格林威治标准时间GMT 格林威治标准时间的正午是太阳抵达天空最高点 ...

  2. 解决一个报表EdmFunction报错问题

        最近测试组提了一个bug,说是某个报表点击查询报错,查看错误log,错误信息如下. 类型"Ticket.Data.SqlFuns"上指定的方法"Boolean C ...

  3. 构建之法<第四章>之感悟

    第四章:两人合作内容出处:4.6 两人合作的不同阶段和技巧 本章主要是讲关于合作方面的,文章以刚刚认识的两个人为例!也就是说,他们之前的关系是陌生人,然而在现实当中两人合作也可以有其它的关系,比如说合 ...

  4. sql插入多条数据的sql语句

    sql插入多条数据的sql语句 有三种方法:1.InSert Into <表名>(列名)Select <列名>From <源表名>如:INSERT INTO Ton ...

  5. 提升WordPress站点速度的八个建议

    WordPress是一个很棒的开源程序,几乎我认识的站长朋友当中,粗略估算有80%使用Wordpress.但很棒不等于完美,就在我所认识的这些朋友中,几乎所有人都会抱怨Wordpress太臃肿,运行效 ...

  6. UVa 10561 - Treblecross

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. Android打开新的Activity并同时关闭当前Activity

    Intent it = new Intent(); it.setClass(EditActivity.this, MainActivity.class); it.setFlags(Intent.FLA ...

  8. 解决 “fatal error C1083: ”无法打开包括文件

    添加该项目的附加路径 . 1)右键查看该项目的属性 2)点击配置属性——〉  C/C++  ——〉  常规  ——〉 附加包含目录——〉将缺失文件所在目录添加进去

  9. android listview getviewtypecount和getItemViewType

    package newdemo.jeno.listviewdemo; import android.app.Activity;import android.os.Bundle;import andro ...

  10. SrcollView分页加载数据(第二种方法 自定义listView)

    package com.baidu.ms; import android.content.Context;import android.util.AttributeSet;import android ...