• 杭电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;
    }
    
  • 相关阅读:
    【go语言】Windows下go语言beego框架安装
    分页
    MongoDB用户与权限管理
    MongoDB安装在Centos7下安装
    centos7安装mysql5.7.33 tar包方式
    文件路径分隔符
    python之批量打印网页为pdf文件
    Python驱动SAP GUI完成自动化(五)
    动态内存与智能指针
    关联容器
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900192.html
Copyright © 2020-2023  润新知