zoukankan      html  css  js  c++  java
  • hdu1896 bjfu1268 水题

    很简单的模拟,我是用的优先队列。不多说,上代码(这是bjfuoj的,hdu的要稍改一下):

    /*
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    
    typedef struct Stone {
        int p, d;
        Stone(int pp, int dd) {
            p = pp;
            d = dd;
        }
    } Stone;
    
    inline bool operator<(const Stone &s1, const Stone &s2) {
        if (s1.p != s2.p) {
            return s1.p > s2.p;
        }
        return s1.d > s2.d;
    }
    
    //输入非负整数,用法int a = get_int();
    int get_int() {
        int res = 0, ch;
        while (!((ch = getchar()) >= '0' && ch <= '9')) {
            if (ch == EOF)
                return -1;
        }
        res = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9')
            res = res * 10 + (ch - '0');
        return res;
    }
    
    
    int main() {
        int n, p, d, ans;
        bool flag;
        while ((n = get_int()) > 0) {
            priority_queue<Stone> pq;
            for (int i = 0; i < n; i++) {
                p = get_int();
                d = get_int();
                pq.push(Stone(p, d));
            }
            ans = 0;
            flag = true;
            while (!pq.empty()) {
                Stone s = pq.top();
                ans = s.p;
                pq.pop();
                if (flag) {
                    s.p += s.d;
                    pq.push(s);
                }
                flag = !flag;
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    Oracle安装
    自动化测试开发
    Hyperf 接入阿里云ACM应用配置管理中心
    PHP redis有序集合实现分页
    虚拟现实与大数据
    树形数据结构化
    立即执行函数
    jQuery中的显示与隐藏
    jQuery中的HTML
    Django+Nginx配置+前后端交互
  • 原文地址:https://www.cnblogs.com/moonbay/p/4262908.html
Copyright © 2011-2022 走看看