题意:给你n只小牛的身高H和体重W(1<=n<=1000),给你三个整数A,B,C,满足A*(H-h) + B*(W-w) <= C的一堆小牛可以组成一个队伍,h和w分别是这个队伍中最小的身高和最小的体重(不一定是同一头牛),问你这个队伍最多多少人
输入
8 //n
1 2 4 //A B C
5 1 //每只小牛的身高体重
3 2
2 3
2 1
7 2
6 4
5 1
4 3
输出
5 //表示1,2,3,4,7这5只小牛一队
思路
代码
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
#define maxn 1005
struct Point {
int w, h, k;
}a[maxn],*sh[maxn],*sk[maxn];
int n, cw, ch, A, B, C;
int ans, cnt, hnum, knum;
bool cmph(Point *a, Point *b) {
return a->h > b->h;
}
bool cmpk(Point *a, Point *b) {
return a->k > b->k;
}
int cal(int h, int w) {
for (; hnum < n&&sh[hnum]->h >= h; hnum++)
if (sh[hnum]->w >= w && sh[hnum]->w <= w + cw)
cnt++;
int k = A * h + B * w + C;
for (; knum<n&&sk[knum]->k>k; knum++)
if (sk[knum]->w >= w && sk[knum]->w <= w + cw)
cnt--;
return cnt;
}
void work(int x) {
cnt = hnum = knum = 0;
int w = sh[x]->w;
int h = sh[x]->h;
for (int i = x; i < n&&sh[i]->h >= h - ch; i++)
if (sh[i]->w >= w && sh[i]->w <= w + cw)
ans = max(ans, cal(sh[i]->h, w));
}
int main() {
scanf("%d", &n);
scanf("%d%d%d", &A, &B, &C);
ch = C / A;
cw = C / B;
for (int i = 0; i < n; i++) {
scanf("%d%d", &a[i].h, &a[i].w);
a[i].k = A * a[i].h + B * a[i].w;
sh[i] = &a[i];
sk[i] = &a[i];
}
sort(sh, sh + n, cmph);
sort(sk, sk + n, cmpk);
ans = 0;
for (int i = 0; i < n; i++)
work(i);
printf("%d\n", ans);
return 0;
}