HDU-1896 Stones 优先队列

  题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896

  优先队列搞就可以了。

 1 //STATUS:G++_AC_234MS_1360KB

 2 #include<stdio.h>

 3 #include<math.h>

 4 #include<stdlib.h>

 5 #include<string.h>

 6 #include<string>

 7 #include<queue>

 8 using namespace std;

 9 #define pii pair<int,int>

10 #define LL __int64

11 const int MAX=100010,INF=0x3f3f3f3f;

12 priority_queue<pii,vector<pii>,greater<pii> > q;

13 int T,n;

14 int main()

15 {    

16 //    freopen("in.txt","r",stdin);

17     int i,j,p,d,ans;

18     pii t;

19     scanf("%d",&T);

20     while(T--){

21         scanf("%d",&n);

22         for(i=0;i<n;i++){

23             scanf("%d%d",&p,&d);

24             q.push(make_pair(p,d));

25         }

26         i=1;

27         while(!q.empty()){

28             if(i){

29                 t=q.top();

30                 p=t.first,d=t.second;

31                 q.pop();    

32                 q.push(make_pair(p+d,d));

33             }

34             else {

35                 ans=q.top().first;

36                 q.pop();

37             }

38             i=!i;

39         }

40         printf("%d\n",ans);

41     }

42     return 0;

43 }

你可能感兴趣的:(优先队列)