HDU 6012 Lotus and Horticulture(离散化)
题目代号: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
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.__
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]$.
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
# 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(离散化)的更多相关文章
- hdu 6012 Lotus and Horticulture 打标记
http://acm.hdu.edu.cn/showproblem.php?pid=6012 我们希望能够快速算出,对于每一个温度,都能够算出它在这n颗植物中,能得到多少价值. 那么,对于第i科植物, ...
- 【HDU】6012 Lotus and Horticulture (BC#91 T2)
[算法]离散化 [题解] 答案一定存在于区间的左右端点.与区间左右端点距离0.5的点上 于是把所有坐标扩大一倍,排序(即离散化). 让某个点的前缀和表示该点的答案. 初始sum=∑c[i] 在l[i] ...
- Lotus and Horticulture
Lotus and Horticulture Accepts: 91 Submissions: 641 Time Limit: 4000/2000 MS (Java/Others) Memory Li ...
- BestCoder Round #91 1002 Lotus and Horticulture
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6012 题意: 这几天Lotus对培养盆栽很感兴趣,于是她想搭建一个温室来满足她的研究欲望. Lotus ...
- HDU 4941 Magical Forest 【离散化】【map】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...
- HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...
- hdu 4325 Flowers(区间离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others) Mem ...
- HDU 5258 数长方形【离散化+暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others) Me ...
- [hdu 4417]树状数组+离散化+离线处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...
随机推荐
- c#中抽象类和接口的相同点跟区别
下面是自己写的一个demo,体现抽象类和接口的用法. using System; using System.Collections.Generic; using System.Linq; using ...
- Git介绍、安装、命令和实战
一.Git介绍 Git是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理. 二.Git安装(Mac系统) 在Git官网下载安装包双击直接安装 在终端输入git来检测Git ...
- 2017.10.21 C组比赛总结
今天考得不太好,只拿了100+0+0+30=130分... [GDKOI训练]音乐节拍 考场AC了! 其实就是大水一道! 思路:二分查找 每次输入后,输出该时刻所在的区间的编号就好了. 总体难度:★★ ...
- C++中的自定义内存管理
1,问题: 1,new 关键字创建出来的对象位于什么地方? 1,位于堆空间: 2,有没有可能位于其它地方? 1,有: 2,通过一些方式可以使动态创建的对象位于静态存储区: 3,这个存储区在程序结束后释 ...
- Python 入门之 内置模块 -- sys模块
Python 入门之 内置模块 -- sys模块 1.sys模块 sys模块是与python解释器交互的一个接口 print(sys.path) #模块查找的顺序 print(sys.argv) # ...
- [.net core]10.请求静态文件, 自定义默认文件名
何谓静态文件,文件系统上的文件, css, javascript , image. html 这些都属于静态文件, .net core web app 默认是不处理文件请求的. 我们来做一个实验 ...
- 在 Chrome DevTools 中调试 JavaScript 入门
第 1 步:重现错误 找到一系列可一致重现错误的操作始终是调试的第一步. 点击 Open Demo. 演示页面随即在新标签中打开. OPEN DEMO 在 Number 1 文本框中输入 5. 在 N ...
- group_concat默认长度限制
这几天做后台一个订单汇总数据报表时,发现当使用group_concat函数时,发现会漏掉数据,究其原因是因为这个函数有默认长度显示1024 可以修改mysql配置文件my.ini 设置group_co ...
- CentOs7 防火墙的开放与关闭及端口的设定
1.查看firewall服务状态 systemctl status firewalld 2.查看firewall的状态 firewall-cmd --state 3.开启.重启.关闭.firewall ...
- 【vue】iView-admin2.0动态菜单路由【版2】
依照iView-admin2.0动态菜单路由[版1] 归纳几个节点动态路由获取方式2 ——> easymock假数据 ——> 数据转组件处理.addRoutes ——> localS ...