HDU 4864(Task)

来源:互联网 发布:淘宝刷客究竟犯不犯法 编辑:程序博客网 时间:2024/05/16 12:53

题意:略。

思路:贪心。题目很特别的给出了获得金钱的计算公式为500*x+2*y,y<=100,所以可以按任务时间从大到小排序,

然后每个任务找出大于该任务难度且与难度最接近的机器完成该任务。

#include <set>#include <cstdio>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int N = 100005;struct Task {    int x, y;    bool operator<(const Task &rhs) const {        if(x == rhs.x)            return y > rhs.y;        return x > rhs.x;    }} task[N];int main() {    int n, m;    while(cin >> n >> m) {        multiset<int> S[105];        LL ans = 0;        int maxLevel = 0, count = 0;        for(int i = 0; i < n; i++) {            int x, y;            scanf("%d%d", &x, &y);            S[y].insert(x);            maxLevel = max(maxLevel, y);        }        for(int i = 0; i < m; i++) {            scanf("%d%d", &task[i].x, &task[i].y);        }        sort(task, task + m);        for(int i = 0; i < m; i++) {            int x = task[i].x;            int y = task[i].y;            for(int j = y; j <= maxLevel; j++) {                if(S[j].empty())                    continue;                multiset<int>::iterator iter = S[j].lower_bound(x);                if(iter == S[j].end() || *iter < x) {                    continue;                } else {                    count++;                    ans += 500ll * x + 2ll * y;                    S[j].erase(iter);                    break;                }            }        }        cout << count << " " << ans << endl;    }    return 0;}


0 0