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 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...
随机推荐
- Elasticsearch-索引新数据(创建索引、添加数据)
ES-索引新数据 0.通过mapping映射新建索引 CURL -XPOST 'localhost:9200/test/index?pretty' -d '{ "mappings" ...
- Spring MVC 跳转页面的方法
转一个Spring MVC 跳转页面的方法,楼主总结的很全面,留着备用. https://blog.csdn.net/c_royi/article/details/78528758
- C++中的三种继承方式
1,被忽略的细节: 1,冒号( :)表示继承关系,Parent 表示被继承的类,public 的意义是什么? class Parent { }; class Child : public Parent ...
- PHP:ReflectionClass
一.简介 ReflectionClass 类报告了一个类的有关信息 ReflectionException 类继承Exception 二.常用函数 ReflectionClass::__constru ...
- Windows7下Pycharm安装Keras
1.安装Anaconda3 2.安装Pycharm 3.安装TensorFlow 一.File -> Settings -> Install 二.搜索TensorFlow -> In ...
- RateLimit--使用guava来做接口限流
转:https://blog.csdn.net/jiesa/article/details/50412027 一.问题描述 某天A君突然发现自己的接口请求量突然涨到之前的10倍,没多久该接口几乎不 ...
- Jade学习(三)之语法规则下
jade可以自动识别单双标签 // 1.jade内容: input(type="button", value="点击") div // 此时输出❌error:i ...
- luogu P4076 [SDOI2016]墙上的句子
luogu loj 题意看了我半天(逃 (应该是我语文太差了) 题意是要确定每一行和每一列的看单词的顺序,使得同时正着出现和反着出现在里面的单词数量最少,每行和每列的性质是这一行所有单词反过来的单词要 ...
- knative 安装
knative 安装 本文安装版本 knative 0.6. 准备 安装 knative 前需要事先安装 Kubernetes 集群 和 Istio. 安装 下载安装所需要的文件.以下选择的是全安装, ...
- vue学习【四】vuex快速入门
大家好,我是一叶,今天我们继续踩坑.今天的内容是vuex快速入门,页面传值不多的话,不建议vuex,直接props进行父子间传值就行,使用vuex就显得比较臃肿. 我们先预览一下效果,如图1所示. 图 ...