POJ - 2008 Moo University - Team Tryouts

题目描述

给定dn组数据, 数据包括w, h, 给定a, b, c;
求一个子集, 子集里面所有的元素都满足A*(H-h) + B*(W-w) <= C
w为子集里面最小的w , h表示子集里面最小的h

样例

Sample Input
8
1 2 4
5 1
3 2
2 3
2 1
7 2
6 4
5 1
4 3
Sample Output
5

思路

  • 题目上的要求, 可以将题目转换用一个直角三角形,去圈点, 求圈得到的最多点的数量
  • 将数据按照h从大到小排序, 可以得到三角形的斜边是从上往下平移的,我们就按照这样一个顺序去遍历数组, 用队列保存满足要求的所有答案
  • 每组数据,保存ah+bw, 用于比较这组数据与当前确定的三角形是否满足要求, 将题目要求化简后合用得到 要求为a * h+b * w <= mh * a + mw * b + c
  • 用优先级队列, 队头保存最大的 a * h + b * w 这样每次就将更新了m后的不满足的答案弹出去
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

const int N = 1010;

struct node
{
	int w, h, s;
	bool operator <(const node &a) const {
		return s < a.s;
	}
};

node t[N];
int a, b, c, n;

bool cmp(node a, node b)
{
	return a.h > b.h;
}

int main()
{
	
	while(~scanf("%d%d%d%d", &n, &a, &b, &c))
	{
		for(int i = 0; i < n; i++)
		{
			scanf("%d%d", &t[i].h, &t[i].w);
			t[i].s = a * t[i].h + b * t[i].w;
		}
		sort(t, t + n, cmp);
		priority_queue<node> q;
		int ans = 0;
		for(int i = 0; i < n; i++)
		{
			int mh = t[i].h;
			int mw = t[i].w;
			while(q.size())
				q.pop();
			for(int j = 0; j < n; j++)
			{
				if(t[i].s > mh * a + mw * b + c)
					break;
				mh = min(mh, t[j].h);
				if(t[j].s <= mh * a + mw * b + c)
				{	
					if(t[j].w >= mw)
						q.push(t[j]);
					while(q.size() && q.top().s > mh * a + mw * b + c)
						q.pop();
				}
				ans = max(ans, (int)q.size());
			}
		}
		printf("%d\n", ans);
	}
		
	return 0;
} 
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值