zoukankan      html  css  js  c++  java
  • HDU 1896 Stones --优先队列+搜索

    一直向前搜。。做法有点像模拟。但是要用到出队入队,有点像搜索。

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    using namespace std;
    #define N 100003
    
    struct node
    {
        int p,d;
        bool operator <(const node &a)const
        {
            if(p == a.p)
                return d>a.d;
            return p>a.p;
        }
    }stone[N];
    
    int maxdis;
    priority_queue<node> que;
    
    void GO()
    {
        node now,next;
        int OE = 1;
        while(!que.empty())
        {
            now = que.top();
            que.pop();
            if(OE)
            {
                next.p = now.p + now.d;
                next.d = now.d;
                que.push(next);
                maxdis = max(next.p,maxdis);
                OE = 0;
            }
            else
                OE = 1;
        }
    }
    
    int main()
    {
        int t,i,p,d,n;
        scanf("%d",&t);
        while(t--)
        {
            maxdis = 0;
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d%d",&stone[i].p,&stone[i].d);
                que.push(stone[i]);
            }
            GO();
            printf("%d
    ",maxdis);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    [转]用mamcache 存储session的好处
    [转]怎么写 JQuery插件 (案例原理)
    关于查询优化
    HBase Canary
    HBase Bulk Loading
    有用的技术网站
    HBase 运维分析
    HBase rest
    hbase mlockall
    Jamon
  • 原文地址:https://www.cnblogs.com/whatbeg/p/3574452.html
Copyright © 2011-2022 走看看