zoukankan      html  css  js  c++  java
  • HDU 1896

    Stones

    Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
    Total Submission(s): 458 Accepted Submission(s): 264


    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
     1 #include <iostream>
     2 #include <vector>
     3 #include <queue>
     4 using namespace std;
     5 
     6 typedef pair<int,int> TWICE;
     7 
     8 int main()
     9 {
    10     int i,j,k,T; 
    11     int N, p, d;  
    12     cin>>T;
    13     while (T--) 
    14     {
    15         priority_queue <TWICE, vector <TWICE>, greater <TWICE> > q;//两个均排序 
    16         cin>>N;
    17         for (i = 1; i <= N; ++i) 
    18         {
    19             cin>>p>>d;
    20             q.push(make_pair(p,d));
    21         }
    22         int cnt = 0, max = 0;
    23         while (!q.empty()) 
    24         {
    25             cnt++;
    26             TWICE u = q.top(); 
    27             q.pop();
    28             if (cnt&1) 
    29                q.push(make_pair(u.first + u.second, u.second));
    30             else 
    31                max = u.first;
    32         }
    33         cout<<max<<endl;
    34     }   
    35     //while (1);
    36     return 0;
    37 }

     运算符重载:

    struct node         //直接在结构体里边定义小于运算符
    {
         int position,length;
         bool operator < (const node &p) const     //定义小于操作符,也可以把&去掉,不用引用类型,时间一样
         {
             if(position != p.position)
                 return position > p.position;
             else
                 return length > p.length;
         }

    };
    priority_queue<node> s; //优先队列--从小到大排序

  • 相关阅读:
    ios 视频旋转---分解ZFPlayer
    IOS lame库 pcm转mp3 分析(方案二)
    IOS lame库 pcm转mp3 分析(方案一)
    ios 动态库合成包(真机&模拟器)脚本
    lame 制作ios静态库
    React Native scrollview 循环播放
    React Native Image多种加载图片方式
    汉字转拼音(包含多音字)
    React Native Alert、ActionSheet
    React Native Picker (城市选择器)
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2662955.html
Copyright © 2011-2022 走看看