http://acm.hdu.edu.cn/showproblem.php?pid=5437
Good understanding of the topic, if violent words or timeouts, you can consider the priority queue can be very simple to solve the problem
1#include <queue>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 structPoint {7 intX,id;8 CharMax201];9 BOOL operator< (ConstPoint & Q)ConstTen { One if(x==q.x)returnq.id<ID; A returnx<q.x; - } - }; thePoint pe[150001]; - intnex[150001],a[150001]; - intMain () - { + intt,n,m,z,i,x,y,w; - while(~SCANF ("%d",&t)) + { A while(t--) at { -scanf" %d%d%d",&n,&m,&z); -memset (NEX,0,sizeof(NEX)); - for(i=1; i<=n;i++) - { -scanf"%s", pe[i].na); inscanf"%d",&pe[i].x); -Pe[i].id=i; to } + while(m--) - { thescanf"%d%d",&x,&y); *nex[x]+=y; $ }Panax Notoginsengnex[n]=N; - intans=1; thePriority_queue<point>que; + for(i=1; i<=n;i++) A { the Que.push (Pe[i]); + while(nex[i]--) - { $ if(que.size () = =0) Break; $Point temp=que.top (); Que.pop (); -a[ans++]=temp.id; - } the } - while(z--)Wuyi { thescanf"%d",&W); - if(z!=0) printf ("%s", pe[a[w]].na); Wu Elseprintf"%s\n", pe[a[w]].na); - } About } $ } - return 0; -}
Hdu 5437 Alisha ' s Party (priority queue)