码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5437 Alisha’s Party (优先队列)

时间:2015-09-14 22:31:55      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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

题目意思比较好理解,如果暴力的话或超时,可以考虑到用优先队列就可以很简单的解决问题

 

 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 }

 

hdu 5437 Alisha’s Party (优先队列)

标签:

原文地址:http://www.cnblogs.com/JJCHEHEDA/p/4808198.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!