zoukankan      html  css  js  c++  java
  • P2672 推销员

    贪心,水题

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 1000000;
    struct house
    {
        int s;
        int a;
        int value;
    }hs[maxn];
    bool operator < (house a, house b) {
        return a.value<b.value;
    }
    int main() {
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++) {
            cin >> hs[i].s;
        }
        for(int i = 1; i <= n; i++) {
            cin >> hs[i].a;
            hs[i].value = hs[i].s * 2 + hs[i].a;
        }
        sort(hs+1, hs+n+1);
        cout << hs[n].value << endl;
        int changed = true;
        int last = n;
        for(int i = 2; i <= n; i++) {
            if(changed) {
                for(int j = 1; j <= n; j++) {
                    if(hs[j].s < hs[last].s) {
                        hs[j].value = hs[j].a;
                    }
                    else if(hs[j].s > hs[last].s) {
                        hs[j].value = hs[j].a + (hs[j].s-hs[last].s)*2;
                    }
                }
                sort(hs, hs+n);
                changed = false;
            }
            int ans = 0;
            for(int j = 1; j <= i; j++) {
                ans += hs[n-j+1].value;
                if(hs[n-j+1].s > last) {
                    changed = true;
                    last = n-j+1;
                }
            }
            cout << ans << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    字符串哈希
    codeforces#766 D. Mahmoud and a Dictionary (并查集)
    莫比乌斯反演模板
    马拉车模板
    codeforces#580 D. Kefa and Dishes(状压dp)
    1076E
    448C
    543A
    295B
    poj3974 Palindrome
  • 原文地址:https://www.cnblogs.com/gengchen/p/6023606.html
Copyright © 2011-2022 走看看