zoukankan      html  css  js  c++  java
  • HDU 1896 Stones (优先队列)

    Problem Description

    Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. 
    There are many stones on the road, when he meet a stone, he will throw it ahead as far as possible if it is the odd stone he meet, or leave it where it was if it is the even stone. Now give you some informations about the stones on the road, you are to tell me the distance from the start point to the farthest stone after Sempr walk by. Please pay attention that if two or more stones stay at the same position, you will meet the larger one(the one with the smallest Di, as described in the Input) first. 

    Input

    In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. 
    For each test case, I will give you an Integer N(0<N<=100,000) in the first line, which means the number of stones on the road. Then followed by N lines and there are two integers Pi(0<=Pi<=100,000) and Di(0<=Di<=1,000) in the line, which means the position of the i-th stone and how far Sempr can throw it.

    Output

    Just output one line for one test case, as described in the Description.

    Sample Input

    2
    2
    1 5
    2 4
    2
    1 5
    6 6
    

    Sample Output

    11
    12
    

    Author

    Sempr|CrazyBird|hust07p43

    Source

    HDU 2008-4 Programming Contest
     1 #include<iostream>
     2 #include<queue>
     3 using namespace std;
     4 struct node//石头
     5 {
     6     int pos,dis;//pos表示位置,dis表示距离
     7 };
     8 struct cmp//queue的比较函数
     9 {
    10     bool operator()(node a,node b)
    11     {
    12         if(a.pos==b.pos)return a.dis>b.dis;
    13         return a.pos>b.pos;//top是最小
    14     }
    15 };
    16 int n,num;//n表示石头的个数,num表示遇到的石头序号
    17 int main()
    18 {
    19     int T;
    20     cin>>T;
    21     while(T--)
    22     {
    23         cin>>n;
    24         priority_queue<node,vector<node>,cmp>Q;
    25         node stone;
    26         for(int i=0;i<n;i++)
    27         {
    28             cin>>stone.pos>>stone.dis;
    29             Q.push(stone);
    30         }
    31         num=0;
    32         while(!Q.empty())//没有可投掷的石头时,一直pop top
    33         {
    34             stone=Q.top();
    35             Q.pop();
    36             num++;
    37             if(num%2==1)
    38             {
    39                 stone.pos+=stone.dis;
    40                 Q.push(stone);
    41             }
    42         }
    43         cout<<stone.pos<<endl;
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    Douglas-Peucker 轨迹压缩算法
    Marching squares 算法 获取轮廓(contour tracing)
    创建Mesh->格子地图转NavMesh->可破坏墙壁
    StretchedBillboard 实现
    程序员的微创业
    买云服务器有推荐吗?国内知道有腾讯云、阿里云...等等,不知道该选哪个好了,另外优惠吗?
    我的阿里云5年
    2021阿里云、腾讯云、华为云、滴滴云评测比较
    终于找到可以一文多发的平台了!
    2019年最新阿里云主机优惠购买指南
  • 原文地址:https://www.cnblogs.com/Annetree/p/5662515.html
Copyright © 2011-2022 走看看