zoukankan      html  css  js  c++  java
  • HDOJ 1896 Stones

    Stones

    Time Limit : 5000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
    Total Submission(s) : 4   Accepted Submission(s) : 3

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    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

    题意是,路上有一堆石头,每次遇到一个石头,如果是奇数个,就将它扔出pi米远,如果是偶数,

    则忽略它,如果同一个位置有多个石头,则扔出轻的(扔出距离近的)。问最后一个石头的位置。

    可以使用优先队列进行模拟。

    #include<iostream>
    #include<queue>
    using namespace std;
    struct node
    {
        int pi;
        int di;
        node(int _di,int _pi):pi(_pi),di(_di){}
        node(){}
        friend bool operator <(node a,node b){
            if(a.di!=b.di)return a.di>b.di;
            else return a.pi>b.pi;
        }
    };
    int main()
    {
        int T,N,i,di,pi;
        cin>>T;
        while(T--)
        {
            int imax=0;
            priority_queue<node>p;
            cin>>N;
            while(N--)
            {
                cin>>di>>pi;
                p.push(node(di,pi));
            }
            int ran=0;
            while(p.size())
            {
                ran++;
                node c=p.top();p.pop();
                if(c.di>imax)imax=c.di;
                if(ran%2!=0)
                    p.push(node(c.di+c.pi,c.pi));
            }
            cout<<imax<<endl;
        }
        return 0;
    }
    


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    我们用的信息系统安全吗?
    硬件代理服务器的日志分析方法
    Solarwinds Orion NPM实战视频演示
    网络资源管理系统LANsurveyor实战体验
    2013年,我的推荐博客汇总
    如何精准高效的实现视觉稿?------前端开发辅助工具AlloyDesigner使用介绍
    SVG如何做圆形图片
    canvas绘制一定数目的圆(均分)
    如何禁止火狐onblur时alert()产生类似选中的拖蓝效果
    ABCD多选正则表达式
  • 原文地址:https://www.cnblogs.com/Thereisnospon/p/4768482.html
Copyright © 2011-2022 走看看