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;
}