题目链接:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1609 真是好题啊。。。关于题解可以参考这三个地址: POJ 2008 Moo University - Team Tryouts 牛题 poj 2008 Moo University - Team Tryouts 解题报告2 March 2004 Green problems with analysis #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define X first #define Y second #define MEMSET(a, b) memset(a, b, sizeof(a)) using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef vector vi; typedef vi::iterator vi_it; typedef map mii; typedef priority_queue pqi; typedef priority_queue , greater > rpqi; typedef priority_queue pqp; typedef priority_queue , greater > rpqp; const int MAX_N = 1000 + 2; typedef struct cow { int w; int h; int k; } *pcow; cow cw[MAX_N]; pcow sort_w[MAX_N]; pcow sort_k[MAX_N]; bool cmp_w(const pcow &c1, const pcow &c2) { return c1->w < c2->w; } bool cmp_k(const pcow &c1, const pcow &c2) { return c1->k < c2->k; } struct rcmp { bool operator () (const pcow &c1, const pcow &c2) { return c1->w > c2->w; } }; int main(int argc, char *argv[]) { // freopen("D:\\in.txt", "r", stdin); int n, a, b, c, i, j; cin >> n >> a >> b >> c; for (i = 0; i < n; ++i) { cin >> cw[i].h >> cw[i].w; cw[i].k = a * cw[i].h + b * cw[i].w; sort_w[i] = cw + i; sort_k[i] = cw + i; } sort(sort_w, sort_w + n, cmp_w); sort(sort_k, sort_k + n, cmp_k); sort_w[n] = new cow(); sort_w[n]->w = 0; priority_queue , rcmp> q; int ans = 0; for (i = 0; i < n; ++i) { int pos = 0, cnt = 0; while (!q.empty()) { q.pop(); } for (j = 0; j < n && sort_w[j]->w <= cw[i].w; ++j) { if (sort_w[j]->w == sort_w[j + 1]->w) { continue; } int lmt = a * cw[i].h + b * sort_w[j]->w + c; while (pos < n && sort_k[pos]->k <= lmt) { if (sort_k[pos]->h >= cw[i].h && sort_k[pos]->w >= sort_w[j]->w) { q.push(sort_k[pos]); ++cnt; } ++pos; } if (cnt > ans) { ans = cnt; } while (!q.empty() && q.top()->w == sort_w[j]->w) { q.pop(); --cnt; } } } cout << ans << endl; return 0; }