zoukankan      html  css  js  c++  java
  • 杭电1896 queue 优先队列

    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

    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    struct node
    {
        friend bool operator<(node a1,node a2)//优先队列 判断 
        {
            if(a1.a==a2.a)  //如果石头的位置一样 这扔的远的排在队列前面
                return a1.b>a2.b;
            return a1.a>a2.a;
        }
        int a,b;
    }as;
    int main()
    {
        int i,j,k,l;
        cin>>l;
        while(l--)
        {
            cin>>k;
            priority_queue<node>a;
            for(i=0;i<k;i++)
            {
                cin>>as.a>>as.b;
                a.push(as);//入队
            }
            int n=1,sum=0;
            while(!a.empty())//如果队列为空 结束
            {
                as=a.top();
                a.pop();
                if(n%2!=0)//如果 步数为偶数 进行 丢石子
                {
                    as.a+=as.b;//石子被丢到的位置
                    sum=as.a;
                    a.push(as);//入队
                }
                n++;
            }
            cout<<sum<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    (4)路由器和交换机区别
    (3)arp协议
    (2)OSi模型
    (1)网络基础概念
    探索JVM底层奥秘ClassLoader源码分析
    数据库类型对应Java语言类型表
    JSON空值处理与 StringUtils工具类使用
    props、state、forms
    React官方中文文档【安装】
    搭建React项目环境【1】
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900192.html
Copyright © 2011-2022 走看看