Alisha’s Party

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1079    Accepted Submission(s): 297

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 2http://write.blog.csdn.net/postedit
1 2 3
 
Sample Outputhttp://write.blog.csdn.net/postedit
Sorey Lailah Rose
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5449 5448 5447 5446 5445 
 

优先队列+模拟,en,应该还行,时间上应该不会超时了,但是下面问题来了。。。

真的是无力吐槽了,感觉。。。

因为排序的问题,一直错,一直错,一直错,结果拖累的小组最后这个题都没A掉。。。

#include<iostream>
#include<stdio.h>
#include<math.h>
#include <string>
#include<string.h>
#include<map>
#include<queue>
#include<set>
#include<utility>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define eps 1e-8
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define ll long long int
char outname[150005][205];
int coun=0; struct People
{
char name[205];
int value;
int pre;
friend bool operator < (People n1, People n2)
{
if(n1.value != n2.value) return n1.value < n2.value;
return n1.pre > n2.pre;
}
} people[150005]; int main ()
{
//cout<<"&&&"<<endl;
int Case;
rd(Case);
while(Case--)
{
int now=0;
coun=0;
int n,innum,quenum;
rd(n);
rd2(innum,quenum);
for(int i=0; i<n; i++)
{
scanf("%s",&people[i].name);
rd(people[i].value);
people[i].pre = i;
} priority_queue <People> que;
int temp1,temp2;
<span style="background-color: rgb(153, 255, 153);"> for(int i=0; i<innum; i++)
{
rd2(temp1,temp2);
for(int i=now; i<temp1; i++)
que.push(people[i]);//查push和push_back区别 now=temp1;
temp2 = (temp2>que.size() ? que.size() : temp2);
for(int i=0; i<temp2 ; i++)
{
strcpy(outname[coun++],que.top().name);
que.pop();
}
}</span>
int quearr[150005],tempmax=-1;
for(int i=0; i<quenum; i++)
{
rd(quearr[i]);
if(tempmax<quearr[i]) tempmax=quearr[i];
} if( tempmax > coun+1 )
{
for(int i=now; i<n ; i++)
que.push(people[i]);
}
while(!que.empty())
{
strcpy(outname[coun++],que.top().name);
que.pop();
}
for(int i=0; i<quenum; i++)
{
printf("%s",outname[ quearr[i]-1 ]);
if(i<quenum-1) printf(" ");
}
printf("\n");
}
return 0 ;
}

增加一个排序就好了,但是好像还是模拟的有点问题,因为还有一个排序啊,这样就很慢了,所以应该用数组记录下来,遍历模拟。。。

#include<iostream>
#include<stdio.h>
#include<math.h>
#include <string>
#include<string.h>
#include<map>
#include<queue>
#include<set>
#include<utility>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define eps 1e-8
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define ll long long int
char outname[150005][205];
int coun=0;
struct T{
int a,b;
}a[150005];
bool cmp(T x,T y){
return x.a<y.a;
}
struct People
{
char name[205];
int value;
int pre;
friend bool operator < (People n1, People n2)
{
if(n1.value != n2.value) return n1.value < n2.value;
return n1.pre > n2.pre;
}
} people[150005]; int main ()
{
//cout<<"&&&"<<endl;
int Case;
rd(Case);
while(Case--)
{
int now=0;
coun=0;
int n,innum,quenum;
rd(n);
rd2(innum,quenum);
for(int i=0; i<n; i++)
{
scanf("%s",&people[i].name);
rd(people[i].value);
people[i].pre = i;
} priority_queue <People> que;
int temp1,temp2;
for(int i=0; i<innum ;i++) rd2(a[i].a,a[i].b);
sort(a,a+innum,cmp); for(int i=0; i<innum; i++)
{
temp1=a[i].a,temp2=a[i].b;
for(int i=now; i<temp1; i++)
que.push(people[i]);//查push和push_back区别 now=temp1;
//temp2 = (temp2>que.size() ? que.size() : temp2);
for(int i=0; i<temp2 ; i++)
{
if(que.empty()) break;
strcpy(outname[coun++],que.top().name);
que.pop();
}
}
int quearr[150005],tempmax=-1;
for(int i=0; i<quenum; i++)
{
rd(quearr[i]);
// if(tempmax<quearr[i]) tempmax=quearr[i];
} //if( tempmax > coun+1 )
// {
for(int i=now; i<n ; i++)
que.push(people[i]);
// }
while(!que.empty())
{
strcpy(outname[coun++],que.top().name);
que.pop();
}
for(int i=0; i<quenum; i++)
{
printf("%s",outname[ quearr[i]-1 ]);
if(i<quenum-1) printf(" ");
}
printf("\n");
}
return 0 ;
}

。。。good code。。。

#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <conio.h>
#include <iostream>
using namespace std;
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define ll long long int
#define maxn 100005
#define mod 1000000007
#define pii pair<int,int>
#define maxn 150005
int n,m,t,q,x,y;
struct node
{
int k,v;
friend bool operator <(node a,node b)
{
if(a.v==b.v) return a.k>b.k;
return a.v<b.v;
}
};
char s[maxn][205];
int v[maxn];
int ans[maxn];
int ti[maxn],tot,qq[200];
int main()
{
rd(t);
getchar();
while(t--)
{
rd2(n,m);
getchar();
rd(q);
getchar();
for(int i=1; i<=n; i++)
{
scanf("%s%d",s[i],&v[i]);
}
memset(ti,0,sizeof(ti));
for(int i=1; i<=m; i++)
{
scanf("%d%d",&x,&y);
ti[x]=y;
}
tot=0;
int mt=0;
for(int i=1; i<=q; i++)
{
rd(qq[i]);
mt=mt>qq[i]?mt:qq[i];
}
priority_queue<node> que;
node nn;
int k;
for(int i=1; i<=n; i++)
{
nn.k=i;
nn.v=v[i];
que.push(nn);
if(i==n)
{
while(!que.empty())
{
nn=que.top();
que.pop();
ans[++tot]=nn.k;
if(tot>=mt) break;
}
break;
}
for(int j=1; j<=ti[i]; j++)
{
if(que.empty()) break;
nn=que.top();
que.pop();
ans[++tot]=nn.k;
}
if(tot>=mt) break;
}
for(int i=1; i<=q; i++)
{
printf("%s",s[ans[qq[i]]]);
if(i==q) printf("\n");
else printf(" ");
}
}
return 0;
}

Regional Changchun Online--Alisha’s Party的更多相关文章

  1. 2013 Asia Regional Changchun C

    Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K ( ...

  2. Regional Changchun Online--Elven Postman(裸排序二叉树)

    Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tot ...

  3. Regional Changchun Online--Travel(最小生成树&& 并查集)

    Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

  4. Regional Changchun Online--Ponds

    网址:http://acm.hdu.edu.cn/showproblem.php?pid=5438 Ponds Time Limit: 1500/1000 MS (Java/Others)    Me ...

  5. hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

  6. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  7. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

  8. 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2015ACM/ICPC Asia Regional Changchun Online /HDU 5438 图

    Ponds                                   Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 1310 ...

随机推荐

  1. html之ul标签

    html之无序列表,建议使用样式来定义列表的类型. 通常和li配对使用 可选属性: type:disc 圆点,circle圆圈,square方块 compact:显示效果比正常更小巧 <body ...

  2. iOS 下拉刷新和加载更多 (OC\Swift)

    Swift语言出来之后, 可能还没有第三方的下拉刷新和上提加载, 所以自己用UIRefreshControl控件和UITableView实例的tableFooterView(底部视图)属性结合起来写了 ...

  3. tomcat如何按站点调试本机程序

    1.配置host host地址:c:\windows\system32\drivers\etc 配置本机域名: # localhost name resolution is handled withi ...

  4. Jfinal中定时器的初步探索(二)

    第一篇中增加的是程序代码的实现,本篇我们将通过配置文件进行定时器的配置,减少代码量,提高灵活性. 1.需要用到的文件:quartz.properties,据说这个文件如果没有的话,按默认的走,结果布署 ...

  5. SQL SERVER 生成ORACLE建表脚本

    /****** Object: StoredProcedure [dbo].[GET_TableScript_ORACLE] Script Date: 06/15/2012 13:07:16 **** ...

  6. 多线程编程之Windows同步方式

    在Windows环境下针对多线程同步与互斥操作的支持,主要包括四种方式:临界区(CriticalSection).互斥对象(Mutex).信号量(Semaphore).事件对象(Event).下面分别 ...

  7. [原]网络库libevent在Visual Studio中的使用方法

    libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用select.epoll.kqueue等系统调用管理事件机制.著名分布式缓存软件memcached也 ...

  8. [转]Hibernate重要规则总结

    实体类的编写规则 l        实体类必须具备无参构造方法 l        实体类必须具备数据库标识 l        通常选用无业务意义的逻辑主键作为数据库标识,通常是int/long/Str ...

  9. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  10. Windows 7无线网卡启用wifi共享蓝屏!

    我的笔记本是联想Y460P,装的是Windows 7 Ultiame(x64)系统,通过设置笔记本的无线(Intel WiFi Link 1000 BGN)搭建Wifi环境并共享,使手机能够通过笔记本 ...