题目代号:HDU 6012

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6012

Lotus and Horticulture

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

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 $a_i$ units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the $b_i$ units of research value; temperatures below the lower limit of the appropriate temperature, can provide $c_i$ 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\in[1,50000]$, the number of potted plants.

The next $n$ line, each line contains five integers $l_i,r_i,a_i,b_i,c_i\in[1, 10^9]$.

 
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
 
题目大意:有n种花,[l,r]之间的温度是最适温度,此时研究价值为a,高于r时研究价值为b,低于l时则研究价值为c。在某一温度能达到最大的研究价值是多少。
解题思路:离散化然后更新各个区间的最大值。
之前忘记输入数据量很大,所以使用的cin然后一直超时,,,我以为是map迭代器的原因后面没用map写了一次,然后发现依然超时,,,最后终于发现是cin的原因[气哭]
解法一:map暴力离散,然后迭代器遍历一遍

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define IOS ios::sync_with_stdio(false)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; map<int,LL>M; int main()
{
//freopen("in.txt", "r", stdin);
int t;
scanf("%d",&t);
while(t--)
{
M.clear();
int n;
LL ans=,sum=;
scanf("%d",&n);
int l,r,a,b,c;
for(int i=;i<=n;i++)
{
scanf("%d%d%d%d%d",&l,&r,&a,&b,&c);
M[l<<]+=a-c;
M[(r<<)+]+=b-a;
sum+=c;
}
ans=max(ans,sum);
for(map<int,LL>::iterator p=M.begin();p!=M.end();p++)
{
sum+=p->second;
ans=max(ans,sum);
}
printf("%lld\n",ans);
}
return ;
}

解法二:

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define IOS ios::sync_with_stdio(false)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL;
inline int Scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} int const MAXM=;
LL sum, f[*MAXM], e[*MAXM];
int l[MAXM], r[MAXM], a[MAXM], b[MAXM], c[MAXM]; int main()
{
//freopen("in.txt", "r", stdin);
int t, n, ans, len;
t=Scan();
while(t--) {
n=Scan(), ans=sum=;
for(int i=;i<=n;++i) {
//l[i]=Scan(); r[i]=Scan(); a[i]=Scan(); b[i]=Scan(); c[i]=Scan();
scanf("%d%d%d%d%d",&l[i],&r[i],&a[i],&b[i],&c[i]);
sum+=c[i]; f[++ans]=l[i]; f[++ans]=r[i];
}
sort(f+,f+ans+);
len=unique(f+,f+ans+)-(f+);
mem(e,);
FOR(i,,n) {
l[i]=lower_bound(f+,f+len+,l[i])-f;
r[i]=lower_bound(f+,f+len+,r[i])-f;
e[l[i]<<]+=a[i]-c[i];
e[r[i]<<|]+=b[i]-a[i];
}
LL num=sum;
for(int i=;i<=*len+;++i)
{
sum+=e[i];
num=max(num,sum);
}
printf("%lld\n",num);
}
return ;
}

HDU 6012 Lotus and Horticulture(离散化)的更多相关文章

  1. hdu 6012 Lotus and Horticulture 打标记

    http://acm.hdu.edu.cn/showproblem.php?pid=6012 我们希望能够快速算出,对于每一个温度,都能够算出它在这n颗植物中,能得到多少价值. 那么,对于第i科植物, ...

  2. 【HDU】6012 Lotus and Horticulture (BC#91 T2)

    [算法]离散化 [题解] 答案一定存在于区间的左右端点.与区间左右端点距离0.5的点上 于是把所有坐标扩大一倍,排序(即离散化). 让某个点的前缀和表示该点的答案. 初始sum=∑c[i] 在l[i] ...

  3. Lotus and Horticulture

    Lotus and Horticulture Accepts: 91 Submissions: 641 Time Limit: 4000/2000 MS (Java/Others) Memory Li ...

  4. BestCoder Round #91 1002 Lotus and Horticulture

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6012 题意: 这几天Lotus对培养盆栽很感兴趣,于是她想搭建一个温室来满足她的研究欲望. Lotus ...

  5. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

  6. HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...

  7. hdu 4325 Flowers(区间离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others)    Mem ...

  8. HDU 5258 数长方形【离散化+暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  9. [hdu 4417]树状数组+离散化+离线处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...

随机推荐

  1. 小记---------FLUM负载均衡配置

    sink group允许组织多个sink到一个实体上,sink processors能够提供在组内所有sink之间实现负载均衡的能力,而且在失败的情况下能够进行故障转移从一个sink到另一个sink, ...

  2. 手撕ES6--Promise

    手撕ES6--Promise:https://www.jianshu.com/p/0925eae38d2c 手写一个Promise,附源码分析:https://blog.csdn.net/weixin ...

  3. python 安装 colorama 控制台输出彩色文字

    pip install colorama from colorama import Back,Fore,Style # 字体颜色print(Fore.LIGHTBLUE_EX,'HelloWorLd' ...

  4. gitlab 安装、配置

    gitlab 安装.配置 对于企业级的私有 git 仓库,gitlab 是个不错的选择. 今天就来说说 gitlab 的安装.配置. 系统配置建议:最低双核 4G 内存. 当前针对 gitlab 版本 ...

  5. win10 powershell禁止运行脚本解决

    win10 现在默认策略为 Restricted 该策略情况下是禁止在终端下运行脚本文件的,所以我们想要通过powershell 来运行我们的脚本文件的话就需要我们更改其策略才行,如下命令可以帮助你 ...

  6. 吴恩达机器学习101:SVM优化目标

    1.为了描述SVM,需要从logistic回归开始进行学习,通过改变一些小的动作来进行支持向量机操作.在logistic回归中我们熟悉了这个假设函数以及右边的sigmoid函数,下式中z表示θ的转置乘 ...

  7. js将时间戳转化为年月日时分秒

    export const dateFormatter = (nows) => { if (!nows) return '' var now = new Date(nows) var year = ...

  8. Java引用与C语言指针的区别

    1.现象 指针在运行时可以改变其所指向的值(地址)即指向其它变量,而引用一旦和某个对象绑定后就不能再改变,总是指向最初的对象. 2.编译 程序在编译时分别将指针和引用添加到符号表上,符号表上记录的是变 ...

  9. windows挂载nfs

    注意:Win10 Creators Update前只有Win10企业版可以挂载NFS, Creators Update后专业版也可挂载NFS了. 安装 按Win+R输入OptionalFeatures ...

  10. Python面向对象的三大特性之异常处理

    一.错误与异常 程序中难免会出现错误,而错误分为两种 1.语法错误:(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) 2.逻辑错误:(逻辑错误),比如用户输入的不合适等一系 ...