http://acm.hdu.edu.cn/showproblem.php?pid=5437

题目意思比较好理解,有a个朋友来给Alisha怂生日礼物,每个人的礼物各有不同的价值,a个朋友来的有先后顺序,Alisha只开m次门,每次开门的时间是刚好在第x个朋友到门口之后,每次开门放y个来的人中礼物价值大的人进来,如果礼物的价值一样,那么先来的人先进去,如果m次门开完了还有人没进来,那就再开一次门把所有人都放进来。如果暴力的话或超时,可以考虑到用优先队列就可以很简单的解决问题

 

 1 #include<queue>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 struct point {
 7     int x,id;
 8     char na[201];
 9     bool operator <(const point & q) const
10     {
11         if (x==q.x) return q.id<id;
12         return x<q.x;
13     }
14 };
15 point pe[150001];
16 int nex[150001],a[150001];
17 int main()
18 {
19     int t,n,m,z,i,x,y,w;
20     while (~scanf("%d",&t))
21     {
22         while (t--)
23         {
24             scanf("%d %d %d",&n,&m,&z);
25             memset(nex,0,sizeof(nex));
26             for (i=1;i<=n;i++)
27             {
28                 scanf("%s",pe[i].na);
29                 scanf("%d",&pe[i].x);
30                 pe[i].id=i;
31             }
32             while (m--)
33             {
34                 scanf("%d %d",&x,&y);
35                 nex[x]+=y;
36             }
37             nex[n]=n;
38             int ans=1;
39             priority_queue<point> que;
40             for (i=1;i<=n;i++)
41             {
42                 que.push(pe[i]);
43                 while (nex[i]--)
44                 {
45                     if (que.size()==0) break;
46                     point temp=que.top(); que.pop();
47                     a[ans++]=temp.id;
48                 }
49             }
50             while (z--)
51             {
52                 scanf("%d",&w);
53                 if (z!=0) printf("%s ",pe[a[w]].na);
54                 else printf("%s\n",pe[a[w]].na);
55             }
56         }
57     }
58     return 0;
59 }

 

posted on 2015-09-14 21:08  蜘蛛侦探  阅读(237)  评论(0编辑  收藏  举报