hdu 1896 优先队列的应用

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

题目大意:

n个石头,每个在位置p,一个属性d。从最左边开始往右走,遇到一个石头,如果是第奇数次遇到,就把他往前仍d米,偶数次遇到就越过。问最后最远的石头距离起点多少米

思路:考虑用优先队列,如果是第奇数个石头,就修改其位置,入队列,否则,出对列;

View Code
 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 
 5 struct Point{
 6     int pos;
 7     int dis;
 8     bool operator < (const Point  p) const {
 9         if(p.pos!=pos)
10             return p.pos<pos;
11         return p.dis<dis;
12     }
13 };
14 
15 priority_queue<Point>Q;
16 
17 int main(){
18     int _case;
19     scanf("%d",&_case);
20     while(_case--){
21         int n;
22         scanf("%d",&n);
23         while(!Q.empty())Q.pop();
24         Point p,q;
25         while(n--){
26             scanf("%d%d",&p.pos,&p.dis);
27             Q.push(p);
28         }
29         int result=0,count=1;
30         while(!Q.empty()){
31             if(count&1){
32                 q=Q.top();
33                 Q.pop();
34                 q.pos+=q.dis;
35                 result=q.pos;
36                 Q.push(q);
37             }else 
38                 Q.pop();
39             count++;
40         }
41         printf("%d\n",result);
42     }
43     return 0;
44 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值