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

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

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

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

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include <string>
  5. #include<string.h>
  6. #include<map>
  7. #include<queue>
  8. #include<set>
  9. #include<utility>
  10. #include<vector>
  11. #include<algorithm>
  12. #include<stdlib.h>
  13. using namespace std;
  14. #define eps 1e-8
  15. #define pii pair<int,int>
  16. #define INF 0x3f3f3f3f
  17. #define rd(x) scanf("%d",&x)
  18. #define rd2(x,y) scanf("%d%d",&x,&y)
  19. #define ll long long int
  20. char outname[150005][205];
  21. int coun=0;
  22.  
  23. struct People
  24. {
  25. char name[205];
  26. int value;
  27. int pre;
  28. friend bool operator < (People n1, People n2)
  29. {
  30. if(n1.value != n2.value) return n1.value < n2.value;
  31. return n1.pre > n2.pre;
  32. }
  33. } people[150005];
  34.  
  35. int main ()
  36. {
  37. //cout<<"&&&"<<endl;
  38. int Case;
  39. rd(Case);
  40. while(Case--)
  41. {
  42. int now=0;
  43. coun=0;
  44. int n,innum,quenum;
  45. rd(n);
  46. rd2(innum,quenum);
  47. for(int i=0; i<n; i++)
  48. {
  49. scanf("%s",&people[i].name);
  50. rd(people[i].value);
  51. people[i].pre = i;
  52. }
  53.  
  54. priority_queue <People> que;
  55. int temp1,temp2;
  56. <span style="background-color: rgb(153, 255, 153);"> for(int i=0; i<innum; i++)
  57. {
  58. rd2(temp1,temp2);
  59. for(int i=now; i<temp1; i++)
  60. que.push(people[i]);//查push和push_back区别
  61.  
  62. now=temp1;
  63. temp2 = (temp2>que.size() ? que.size() : temp2);
  64. for(int i=0; i<temp2 ; i++)
  65. {
  66. strcpy(outname[coun++],que.top().name);
  67. que.pop();
  68. }
  69. }</span>
  70. int quearr[150005],tempmax=-1;
  71. for(int i=0; i<quenum; i++)
  72. {
  73. rd(quearr[i]);
  74. if(tempmax<quearr[i]) tempmax=quearr[i];
  75. }
  76.  
  77. if( tempmax > coun+1 )
  78. {
  79. for(int i=now; i<n ; i++)
  80. que.push(people[i]);
  81. }
  82. while(!que.empty())
  83. {
  84. strcpy(outname[coun++],que.top().name);
  85. que.pop();
  86. }
  87. for(int i=0; i<quenum; i++)
  88. {
  89. printf("%s",outname[ quearr[i]-1 ]);
  90. if(i<quenum-1) printf(" ");
  91. }
  92. printf("\n");
  93. }
  94. return 0 ;
  95. }

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

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include <string>
  5. #include<string.h>
  6. #include<map>
  7. #include<queue>
  8. #include<set>
  9. #include<utility>
  10. #include<vector>
  11. #include<algorithm>
  12. #include<stdlib.h>
  13. using namespace std;
  14. #define eps 1e-8
  15. #define pii pair<int,int>
  16. #define INF 0x3f3f3f3f
  17. #define rd(x) scanf("%d",&x)
  18. #define rd2(x,y) scanf("%d%d",&x,&y)
  19. #define ll long long int
  20. char outname[150005][205];
  21. int coun=0;
  22. struct T{
  23. int a,b;
  24. }a[150005];
  25. bool cmp(T x,T y){
  26. return x.a<y.a;
  27. }
  28. struct People
  29. {
  30. char name[205];
  31. int value;
  32. int pre;
  33. friend bool operator < (People n1, People n2)
  34. {
  35. if(n1.value != n2.value) return n1.value < n2.value;
  36. return n1.pre > n2.pre;
  37. }
  38. } people[150005];
  39.  
  40. int main ()
  41. {
  42. //cout<<"&&&"<<endl;
  43. int Case;
  44. rd(Case);
  45. while(Case--)
  46. {
  47. int now=0;
  48. coun=0;
  49. int n,innum,quenum;
  50. rd(n);
  51. rd2(innum,quenum);
  52. for(int i=0; i<n; i++)
  53. {
  54. scanf("%s",&people[i].name);
  55. rd(people[i].value);
  56. people[i].pre = i;
  57. }
  58.  
  59. priority_queue <People> que;
  60. int temp1,temp2;
  61. for(int i=0; i<innum ;i++) rd2(a[i].a,a[i].b);
  62. sort(a,a+innum,cmp);
  63.  
  64. for(int i=0; i<innum; i++)
  65. {
  66. temp1=a[i].a,temp2=a[i].b;
  67. for(int i=now; i<temp1; i++)
  68. que.push(people[i]);//查push和push_back区别
  69.  
  70. now=temp1;
  71. //temp2 = (temp2>que.size() ? que.size() : temp2);
  72. for(int i=0; i<temp2 ; i++)
  73. {
  74. if(que.empty()) break;
  75. strcpy(outname[coun++],que.top().name);
  76. que.pop();
  77. }
  78. }
  79. int quearr[150005],tempmax=-1;
  80. for(int i=0; i<quenum; i++)
  81. {
  82. rd(quearr[i]);
  83. // if(tempmax<quearr[i]) tempmax=quearr[i];
  84. }
  85.  
  86. //if( tempmax > coun+1 )
  87. // {
  88. for(int i=now; i<n ; i++)
  89. que.push(people[i]);
  90. // }
  91. while(!que.empty())
  92. {
  93. strcpy(outname[coun++],que.top().name);
  94. que.pop();
  95. }
  96. for(int i=0; i<quenum; i++)
  97. {
  98. printf("%s",outname[ quearr[i]-1 ]);
  99. if(i<quenum-1) printf(" ");
  100. }
  101. printf("\n");
  102. }
  103. return 0 ;
  104. }

。。。good code。。。

  1. #pragma comment(linker, "/STACK:102400000,102400000")
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <queue>
  7. #include <map>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <conio.h>
  11. #include <iostream>
  12. using namespace std;
  13. #define rd(x) scanf("%d",&x)
  14. #define rd2(x,y) scanf("%d%d",&x,&y)
  15. #define ll long long int
  16. #define maxn 100005
  17. #define mod 1000000007
  18. #define pii pair<int,int>
  19. #define maxn 150005
  20. int n,m,t,q,x,y;
  21. struct node
  22. {
  23. int k,v;
  24. friend bool operator <(node a,node b)
  25. {
  26. if(a.v==b.v) return a.k>b.k;
  27. return a.v<b.v;
  28. }
  29. };
  30. char s[maxn][205];
  31. int v[maxn];
  32. int ans[maxn];
  33. int ti[maxn],tot,qq[200];
  34. int main()
  35. {
  36. rd(t);
  37. getchar();
  38. while(t--)
  39. {
  40. rd2(n,m);
  41. getchar();
  42. rd(q);
  43. getchar();
  44. for(int i=1; i<=n; i++)
  45. {
  46. scanf("%s%d",s[i],&v[i]);
  47. }
  48. memset(ti,0,sizeof(ti));
  49. for(int i=1; i<=m; i++)
  50. {
  51. scanf("%d%d",&x,&y);
  52. ti[x]=y;
  53. }
  54. tot=0;
  55. int mt=0;
  56. for(int i=1; i<=q; i++)
  57. {
  58. rd(qq[i]);
  59. mt=mt>qq[i]?mt:qq[i];
  60. }
  61. priority_queue<node> que;
  62. node nn;
  63. int k;
  64. for(int i=1; i<=n; i++)
  65. {
  66. nn.k=i;
  67. nn.v=v[i];
  68. que.push(nn);
  69. if(i==n)
  70. {
  71. while(!que.empty())
  72. {
  73. nn=que.top();
  74. que.pop();
  75. ans[++tot]=nn.k;
  76. if(tot>=mt) break;
  77. }
  78. break;
  79. }
  80. for(int j=1; j<=ti[i]; j++)
  81. {
  82. if(que.empty()) break;
  83. nn=que.top();
  84. que.pop();
  85. ans[++tot]=nn.k;
  86. }
  87. if(tot>=mt) break;
  88. }
  89. for(int i=1; i<=q; i++)
  90. {
  91. printf("%s",s[ans[qq[i]]]);
  92. if(i==q) printf("\n");
  93. else printf(" ");
  94. }
  95. }
  96. return 0;
  97. }

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. 功能更强大的格式化工具类 FormatUtils.java

    package com.util; import java.text.DecimalFormat; import java.text.ParseException; import java.text. ...

  2. 如何进行oracle capability i/o(压力测试数据库服务器i/o性能)

    一 .oracle 有关 IO 信息的相关统计函数 Oracle i/o stack包含hbas,存储相关的交换机.存储物理磁盘.那么oracle建议在应用程序部署的时候,建议去验证i/o避免存在问题 ...

  3. Andaroid L新特性

    1.Material Design”(材料设计)的全新设计理念,和Holo相比,Material Design更加色彩丰富,不像Holo那样灰暗 2.1)卡片风格(锁屏界面) 2)环动式设计  And ...

  4. Android内核剖析读书笔记

    第16章 程序包管理 PackageManagerService類 PmS 目錄 16.1 包管理概述 16.2 packages.xml文件格式 16.3 包管理服務的啟動過程 16.4 應用程序的 ...

  5. 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码

    2013-9-15 1.    CustomValidator验证控件验证用户输入的字符长度 在实际的开发中通常会遇到验证用户输入的字符长度的问题,通常的情况下,可以写一个js的脚本或者函数,在ASP ...

  6. "unresolved external symbol __imp__WSACleanup@0"

    编译时出现这种问题怎么解决:"unresolved external symbol __imp__WSACleanup@0"出现此类问题一般是ws2_32.lib这个lib没有li ...

  7. 黄聪:Xmind修改默认字体风格设置

    Xmind是一款非常好用的思维导图软件,但默认字体使用宋体不够好看,软件本身不支持设置默认字体,但通过修改配置文件达到配置默认字体的目的 默认控制风格的配置文件位置 XMind\plugins\org ...

  8. SDS查看部署在集成TOMCAT服务器中的项目目录结构

  9. POJ 1611 The Suspects(并查集,简单)

    为什么ACM的题意都这么难懂,就不能说的直白点吗?还能不能好好的一起刷题了? 题意:你需要建一个n的并查集,有m个集合,最后要输出包含0的那个集合的元素的个数. 这是简单并查集应用,所以直接看代码吧! ...

  10. POJ 4046 Sightseeing 枚举+最短路 好题

    有n个节点的m条无向边的图,节点编号为1~n 然后有点权和边权,给出q个询问,每一个询问给出2点u,v 输出u,v的最短距离 这里的最短距离规定为: u到v的路径的所有边权+u到v路径上最大的一个点权 ...