题目代号: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. python 并发编程 多线程 GIL与Lock

    GIL与Lock Python已经有一个GIL来保证同一时间只能有一个线程来执行了,为什么这里还需要互斥锁lock? 锁的目的是为了保护共享的数据,同一时间只能有一个线程来修改共享的数据 GIT保证了 ...

  2. zabbix4安装部署

    参考: https://www.cnblogs.com/barneywill/p/10380622.html https://www.cnblogs.com/yinzhengjie/p/1037256 ...

  3. IOMETER的简单使用

    1. 网上下载文件: 一般至少包含两个: 2. 使用IOmeter 进行 功能测试. 注意选择 测试需要的盘 注意 选择的磁盘 会被充满. 会产生一个特别大的文件 3. 选择测试对象 4. 可以查看实 ...

  4. Java第三周总结报告

    本周做了什么? 本周利用Java语言重新回顾了条件结构与循环结构和字符串的处理等问题,认识到了Java与C/C++的在这两个方面的不同. 下周准备做什么? 学习Java面向对象的有关知识,包括对象与类 ...

  5. python之网络部分

    1.C/S B/S架构 C: client端 B: browse 浏览器 S: server端 C/S架构: 基于客户端与服务端之间的通信 ​ QQ, 游戏,皮皮虾, 快手,抖音. ​ 优点: 个性化 ...

  6. jupyter notebook 使用多个python环境

    conda install nb_conda_kernels 执行上面的命令,然后启动notebook就可以选择conda中的所有环境了

  7. Elasticsearch入门教程(二):Elasticsearch核心概念

    原文:Elasticsearch入门教程(二):Elasticsearch核心概念 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:ht ...

  8. RabbitMQ入门教程(八):远程过程调用RPC

    原文:RabbitMQ入门教程(八):远程过程调用RPC 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.cs ...

  9. 简单CSS实现闪烁动画(+1白话讲解)

    原文:简单CSS实现闪烁动画(+1白话讲解) 本文转载于:猿2048网站⇒https://www.mk2048.com/blog/blog.php?id=icj2chj2ab 背景 本文承接自上文&l ...

  10. 前端页面适配的rem换算 为什么要使用rem

    之前有些适配做法,是通过js动态计算viewport的缩放值(initial-scale). 例如以屏幕320像素为基准,设置1,那屏幕375像素就是375/320=1.18以此类推. 但直接这样强制 ...