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;
    }
    
  • 相关阅读:
    如何把方法(函数)当参数传递
    致加西亚的信 摘录
    算法:C#数组去除重复元素算法研究
    [转帖]SQL SERVER 2005 安全设置
    [转].NET学习网站收集
    C#你真的懂了吗 啥叫引用2
    比IETEST更好用的浏览器兼容性测试软件[绿色]
    [转帖]使用asp.net访问Oracle的方法汇总
    影响力密码 信任你自己
    [转]自动刷新页面的实现方法总结
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900192.html
Copyright © 2011-2022 走看看