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;
    }
  • 相关阅读:
    JSP获取input(含正则表达式)
    Computability 7: Exercises
    Network 5: Data Link Layer
    PRML 7: The EM Algorithm
    PRML 6: SVD and PCA
    PRML 5: Kernel Methods
    PRML 4: Generative Models
    Computability 6: Reducibility
    Distributed Hash Table
    Network 4: Network Layer
  • 原文地址:https://www.cnblogs.com/moonbay/p/4262908.html
Copyright © 2011-2022 走看看