poj 1905 (贪心失败 = =)

//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <climits>
#include <map>

using namespace std;

#define SPEED_UP iostream::sync_with_stdio(false);
#define FIXED_FLOAT cout.setf(ios::fixed, ios::floatfield);
#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))
#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))
#define in_bound(l, r, i) (l)<=(i)&&(i)<(r)

typedef long long LL;

const int Maxn = 3000;
const int inf = INT_MAX/2;

struct st{
    int x, y, t, s;
    st(int x, int y, int t, int s):x(x), y(y), t(t), s(s){}
    bool operator < (const st &rhs) const {
        return t > rhs.t;
    }
};

struct Edge{
    int from, to, ci, pi, ri;
};

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int c, l;
vector<pair<int, int> > a, b;

LL solve() {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int i = 0, j = 0, sa = a.size(), sb = b.size(), ans = 0;
    while (i < sa && j < sb) {
        if (a[i].second < b[j].first) {
            ++i;
            continue;
        }
        if (a[i].first > b[j].first) {
            ++j;
            continue;
        }
        ++ans;
        //cout << "cow: " << a[i].first << ' ' << a[i].second << " get " << b[j].first << endl;
        ++i;
        --b[j].second;
        if (b[j].second == 0) ++j;
    }
    return ans;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    SPEED_UP
    while (cin >> c >> l) {
        int x, y;
        a.clear();
        b.clear();
        rep(i, 0, c-1) {
            cin >> x >> y;
            a.push_back(make_pair(x, y));
        }
        rep(i, 0, l-1) {
            cin >> x >> y;
            if (y)
                b.push_back(make_pair(x, y));
        }

        cout << solve() << endl;
    }
    return 0;
}
http://blog.csdn.net/sdj222555/article/details/10698641
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值