hdu 6012 Lotus and Horticulture

本文介绍了一种通过调整温室温度来最大化植物研究价值的方法。给定每个植物的适宜生长温度范围及不同温度下所能提供的研究价值,需选择最佳温度使总研究价值最大。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Lotus and Horticulture

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 549    Accepted Submission(s): 177


Problem Description
These days Lotus is interested in cultivating potted plants, so she wants to build a greenhouse to meet her research desires.

Lotus placed all of the  n  pots in the new greenhouse, so all potted plants were in the same environment.

Each plant has an optimal growth temperature range of  [l,r] , which grows best at this temperature range, but does not necessarily provide the best research value (Lotus thinks that researching poorly developed potted plants are also of great research value).

Lotus has carried out a number of experiments and found that if the growth temperature of the i-th plant is suitable, it can provide  ai  units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the  bi  units of research value; temperatures below the lower limit of the appropriate temperature, can provide  ci  units of research value.

Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of  a b c  are also known. You need to choose a temperature for the greenhouse based on these information, providing Lotus with the maximum research value.

__NOTICE: the temperature can be any real number.__
 

Input
The input includes multiple test cases. The first line contains a single integer  T , the number of test cases.

The first line of each test case contains a single integer  n[1,50000] , the number of potted plants.

The next  n  line, each line contains five integers  li,ri,ai,bi,ci[1,109] .
 

Output
For each test case, print one line of one single integer presenting the answer.
 

Sample Input
  
1 5 5 8 16 20 12 10 16 3 13 13 8 11 13 1 11 7 9 6 17 5 2 11 20 8 5
 

Sample Output
  
83
 

Source
 

Recommend
jiangzijing2015   |   We have carefully selected several similar problems for you:   6014  6013  6012  6011  6010 
题意:给n个植物,适宜生长的温度范围是l~r,适宜温度可获得的研究价值为a,高于适宜温度可获得研究价值为b,低于则c,问可获得的最大研究价值是多少。温度只能取整数。

思路:因为是闭区间,故我们先将左端点和右端点+0.5离散化,因为0.5很难处理,故*2就好了,假设一开始取温度为无穷小,则答案为∑c,然后每经过一个左端点,研究价值+a-c,每经过右端点+0.5,研究价值+b-a,故只需要扫一遍记录最大值就好了,但因为温度只能取整数,所以还需要一点小小的处理,详细看代码吧。

#include<cstdio>  
#include<algorithm>  
#include<cstring>  
#include<iostream>  
#include<cmath>  
#include<queue>  
#include<functional>  
typedef long long LL;
using namespace std;
#define maxn 100005
#define ll l,mid,now<<1  
#define rr mid+1,r,now<<1|1  
#define lson l1,mid,l2,r2,now<<1  
#define rson mid+1,r1,l2,r2,now<<1|1  
#define inf 0x3f3f3f3f  
const int mod = 1e9 + 7;
struct node{
	int value, pos;
}p[maxn];
bool cmp(node a, node b){
	return a.pos < b.pos;
}
int main(){
	int t;
	scanf("%d", &t);
	while (t--){
		int n;
		scanf("%d", &n);
		int len = 0;
		LL ans = 0;
		while (n--){
			int l, r, a, b, c;
			scanf("%d%d%d%d%d", &l, &r, &a, &b, &c);
			ans += c;
			p[len].pos = l << 1;
			p[len++].value = a - c;
			p[len].pos = r << 1 | 1;
			p[len++].value = b - a;
		}
		sort(p, p + len, cmp);
		LL maxnum = ans;
		for (int i = 0; i < len; i++){
			ans += p[i].value;
			while (p[i + 1].pos == p[i].pos){
				ans += p[++i].value;
			}
			maxnum = max(maxnum, ans);
		}
		printf("%lld\n", maxnum);
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值