• 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;
    }
  • 相关阅读:
    MySQL主从复制与读写分离
    MySQL主从同步、读写分离配置步骤
    c# 无损压缩图片,接口传过来的是字节
    C# 和JAVA AES加密之间的互相兼容,C#版
    list的线程非安全性
    webrequesthelper
    .net core 实现微信登陆
    .net core 实现QQ登陆网站
    c# 深拷贝
    在H+框架下的一个给iframe 的body 添加事件。
  • 原文地址:https://www.cnblogs.com/moonbay/p/4262908.html
Copyright © 2020-2023  润新知