hdu 5437 优先队列+模拟 **
比赛的时候虽然考虑到没门的情况,但是写了几组都能过,就没想了,23333,差一行代码就能A,遗憾~~
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
#define pb(a) push_back(a)
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt,cnt,k;
struct Node
{
int id;
char s[];
int v;
friend bool operator<(Node a,Node b)
{
if(a.v==b.v)
{
return a.id>b.id;
}
return a.v<b.v;
}
}node[MAXN];
struct Node2
{
int b,c;
void in()
{
scanf("%d%d",&b,&c);
}
}node2[MAXN];
int ans[MAXN];
void fun()
{
int i;
priority_queue<Node> q;
Node now;
int sum=,tot=;
for(i=;i<=k;i++)
{
q.push(node[i]);
if(q.size()+sum==node2[tot].b)
{
for(int j=;j<node2[tot].c&&!q.empty();j++)
{
now=q.top();
q.pop();
ans[sum++]=now.id;
}
tot++;
}
}
while(!q.empty())
{
now=q.top();
q.pop();
ans[sum++]=now.id;
}
}
bool cmp(Node2 aa,Node2 bb)
{
return aa.b<bb.b;
}
int main()
{
int i,j,ca=,q;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
scanf("%d%d%d",&k,&m,&q); for(i=;i<=k;i++)
{
scanf("%s%d",&node[i].s,&node[i].v);
node[i].id=i;
}
node2[].b=-;
for(i=;i<m;i++)
{
node2[i].in();
}
sort(node2,node2+m,cmp);
fun();
int qq;
for(i=;i<q;i++)
{
scanf("%d",&qq);
qq--;
if(i==)
{
printf("%s",node[ans[qq]].s);
continue;
}
printf(" %s",node[ans[qq]].s);
}
printf("\n");
} }
hdu 5437 优先队列+模拟 **的更多相关文章
- hdu 5437(优先队列模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
- Alisha’s Party (HDU5437)优先队列+模拟
Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...
- Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...
- 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
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- hdu 5437 Alisha’s Party 优先队列
Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...
- 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 & ICPC 2015 Changchun Alisha's Party(优先队列)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- url中出现井号("#")的问题
今天在asp.net mvc网站项目的前台页面里写一段js代码时,想要跳转到某个url,例如 location.href="xxxx?"+"id="+id+&q ...
- 使用Django——安装
1. 安装 a) 安装python 在http://www.python.org/上下载python 2.7,然后安装,接着将python的安装路径(一般是C:\python27)添加到windows ...
- js判断checkbox状态,处理表单提交事件
功能描述:手机网页需要一个投票功能,通过form的post提交.有5-20个checkbox选项,至少选一项,至多选三项.需要在用户点击提交按钮前,判断checkbox的状态是否符合条件,符合则提交到 ...
- SharePoint更改密码
stsadm –o updatefarmcredentials –userlogin DomainName\UserName -password NewPassword –local 1. 通过管理 ...
- mongoengine
http://docs.mongodb.org/ecosystem/drivers/python/ http://www.cnblogs.com/holbrook/archive/2012/03/11 ...
- QPS计算方法
2016年3月14日 13:55:39 星期一 好久没写文章了, 神烦.....
- Java for LeetCode 218 The Skyline Problem【HARD】
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- Debian 配置apt-get源
1.配置apt-get源 cp /etc/apt/sources.list /etc/apt/sources.listbak #备份原有配置文件 nano /etc/apt/so ...
- QL Server 实用脚本
use MyFirstDB; -- 主要内容 -- SQL Server 实用脚本 -- 1.case语句 -- 2.子查询 -- 3.连接查询 -- 4.脚本变量与流程控制(选择与循环等) -- 5 ...
- 【CCL】连通区域提取
根据朋友给的一份原理写的 感觉还挺清楚 #include "cv.h" #include "highgui.h" #include <stdio.h> ...