Hdu 6012 Lotus and Horticulture 能看懂的思维

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  nn 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][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  aiai units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the  bibi units of research value; temperatures below the lower limit of the appropriate temperature, can provide  cici units of research value. 

Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of  aabbcc 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.__ 
InputThe input includes multiple test cases. The first line contains a single integer  TT, the number of test cases. 

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

The next  nn line, each line contains five integers  li,ri,ai,bi,ci[1,109]li,ri,ai,bi,ci∈[1,109]
OutputFor 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

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
struct ss
{
    double  pos;
    int  val;
}s[150000];
bool cmp( ss x, ss y )
{
    return x.pos < y.pos;
}
int main()
{

    int t;
    scanf("%d", &t);
    while( t-- )
    {
        long long int n , i , j ,a , b , c, l, r ;
       // double l, r;
        long long int sum  = 0;
        scanf("%lld", &n);
        for( i  =0 ; i<n; i++)
        {
            scanf("%lld%lld%lld%lld%lld", &l,&r, &a, &b,&c);
            s[i].pos = l;
            s[i].val = a - c;
            s[i+n].pos = r+0.5;
            s[i+n].val = b-a;
            sum  = sum + c;
        }
        sort( s, s+2*n, cmp);
        long long int maa = 0;
        for( i =0; i<2*n; i++)
        {
            sum = sum+ s[i].val;
            for( (i+1) < 2*n ; s[i+1].pos == s[i].pos && ( i+1)<2*n; )///只可能和后面的相等
            {
                    //printf("%d\n", s[j].val);
                    i++;
                    sum = sum+s[i].val;
            }
            maa = max ( maa, sum);
        }
        printf("%lld\n", maa);
    }
}

  

这几天Lotus对培养盆栽很感兴趣,于是她想搭建一个温室来满足她的研究欲望。
Lotus将所有的nn株盆栽都放在新建的温室里,所以所有盆栽都处于完全相同的环境中。
每一株盆栽都有一个最佳生长温度区间[l,r][l,r],在这个范围的温度下生长会生长得最好,但是不一定会提供最佳的研究价值(Lotus认为研究发育不良的盆栽也是很有研究价值的)。
Lotus进行了若干次试验,发现若第ii株盆栽的生长温度适宜,可以提供a_ia
​i
​​ 的研究价值;若生长温度超过了适宜温度的上限,能提供b_ib
​i
​​ 的研究价值;若生长温度低于适宜温度的下限,则能提供c_ic
​i
​​ 的研究价值。
现在通过试验,Lotus已经得知了每一株盆栽的适宜生长温度范围,也知道了它们的aa、bb、cc的值。你需要根据这些信息,给温室选定一个温度(这个温度可以是任意实数),使得Lotus能获得的研究价值最大。
输入描述
多组数据,第一行一个整数TT表示数据组数
每组数据第一行一个整数n\in[1,50000]n∈[1,50000],表示盆栽数量
接下来nn行每行五个整数l_i,r_i,a_i,b_i,c_i\in[1, 10^9]l
​i
​​ ,r
​i
​​ ,a
​i
​​ ,b
​i
​​ ,c
​i
​​ ∈[1,10
​9
​​ ],意义如上所述
输出描述
每组数据输出一行一个整数表示答案
输入样例
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
输出样例
83

思路:



1、考虑对应最优解的温度,我们首先可以设定它是负无穷,那么此时的价值总和就是所有区间的c的和。



2、然后如果我们枚举增大温度,显然时间复杂度是不允许的,那么我们考虑两个点:

①区间左端点。

②区间右端点+0.5(区间的点都是整数的点我们+0.5就能表示大于这个区间右端点的第一个位子);

很显然,我们当温度枚举到一个区间的左端点的时候,总价值-ci+ai;

我们当温度枚举到一个区间的右端点+0.5的时候,总价值-ai+bi;



那么我们只要有2*N个点,我们就能动态的维护某一个温度的时候的总价值了。

那么我们将输入进来的信息处理成两个点,然后将这些点按照从小到大的顺序排序。

接下来动态维护一下即可。



Ac代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值