hdu5437Java,【优先队列】HDU5437Alisha’s Party【2015 ACM/ICPC Asia Regional Changchun Online】...

Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1724    Accepted Submission(s): 606 Problem Description Jack likes to travel around the world, but he doesn’t like to wait. N

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5437

Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value  v , and all of them will come at a different time. Because the lobby is not large enough, Alisha can only let a few people in at a time. She decides to let the person whose gift has the highest value enter first.

Each time when Alisha opens the door, she can decide to let  p  people enter her castle. If there are less than  p  people in the lobby, then all of them would enter. And after all of her friends has arrived, Alisha will open the door again and this time every friend who has not entered yet would enter.

If there are two friends who bring gifts of the same value, then the one who comes first should enter first. Given a query  n  Please tell Alisha who the  n−th  person to enter her castle is.

Input The first line of the input gives the number of test cases,  T  , where  1≤T≤15 .

In each test case, the first line contains three numbers  k,m  and  q  separated by blanks.  k  is the number of her friends invited where  1≤k≤150,000 . The door would open m times before all Alisha’s friends arrive where  0≤m≤k . Alisha will have  q  queries where  1≤q≤100 .

The  i−th  of the following  k  lines gives a string  Bi , which consists of no more than  200  English characters, and an integer  vi ,  1≤vi≤108 , separated by a blank.  Bi  is the name of the  i−th  person coming to Alisha’s party and Bi brings a gift of value  vi .

Each of the following  m  lines contains two integers  t(1≤t≤k)  and  p(0≤p≤k)  separated by a blank. The door will open right after the  t−th  person arrives, and Alisha will let  p  friends enter her castle.

The last line of each test case will contain  q  numbers  n1,...,nq  separated by a space, which means Alisha wants to know who are the  n1−th,...,nq−th  friends to enter her castle.

Note: there will be at most two test cases containing  n>10000 .

Output For each test case, output the corresponding name of Alisha’s query, separated by a space.

Sample Input

1

5 2 3

Sorey 3

Rose 3

Maltran 3

Lailah 5

Mikleo 6

1 1

4 2

1 2 3

Sample Output

Sorey Lailah Rose

题目意思:Alisha有k个朋友来他家,每个朋友来是有先后次序的,Alisha会开m次门,每次都是在第t个朋友到了以后,他会邀请p个朋友进家门,原则是邀请所带礼物价值高的朋友先进门,如果两个朋友的礼物价值相同,就叫先到的进门。最后等所有朋友都到了以后,Alisha会把他所有的朋友都叫进来,进来的顺序跟先前的要求一样。题目给出q个询问,问第ni个进门的朋友是谁。题目大意:求出一个数比给定的数D大并且此数的二进制中的1的个数再s1,s2之间. 思路:如果直接通过D+1向后暴力的话,必定时超时的,因为输入为300000组,如果给个2^31的D,s1=1,s2=1,那么找每个 二进制值0.1的个数就会执行30次,并且还有循环找数的过程所以会超时.不

题目坑点很多,回忆当时比赛的时候,好像就是因为没有考虑到给t,p排序导致这道题目卡了很久!!!

代码:

#include

#include

#include

using namespace std;

struct node{

string name;

int value;

int id;

friend bool operator

if(a.value!=b.value) return a.value

else return a.id>b.id;

}

}stu[150050],ans[150050];

int d[150];

struct node1{

int a,b;

}s[150050];

bool cmp(node1 A,node1 B)

{

return A.a

}

int main()

{

cin.sync_with_stdio(false); // 不用会超时!

int t,n,m,k,a,b,c;

cin>>t;

while(t--){

priority_queueq;

int cnt=0,p=0;

cin>>n>>m>>k; // n表示有n个人被邀请,m表示有m次开门,k表示最后询问的人数

for(int i=0;i

cin>>stu[i].name>>stu[i].value;

stu[i].id=i;

}

for(int i=0;i>s[i].a>>s[i].b; // a,b分别表示来第t个人的时候进p人!

sort(s,s+m,cmp); // 这里需要注意,题目没有说明给你的t是从小到大的顺序,所以需要我们排一遍顺序!

for(int i=0;i

a=s[i].a;b=s[i].b;

while(a>cnt) q.push(stu[cnt++]);

while(b&&!q.empty()){ // 注意,这里需要判断队列是否为空!!

ans[p++]=q.top();

q.pop();

b--;

}

}

while(cnt

while(!q.empty()){ // 最后将还在队列里已经排好序的抛出到ans的结构体中;

ans[p++]=q.top();

q.pop();

}

for(int i=0;i>d[i];

for(int i=0;i

cout<

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值