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 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...
随机推荐
- python 并发编程 基于gevent模块 协程池 实现并发的套接字通信
基于协程池 实现并发的套接字通信 客户端: from socket import * client = socket(AF_INET, SOCK_STREAM) client.connect(('12 ...
- 单例模式 之 单例模式——Holder
之前我写过 单例模式中的饿汉模式和懒汉模式 他们虽然都能实现单例模式 但是优缺点很明显 饿汉模式:不能懒加载(类加载就会被实例化),消耗很大,在并发情况下安全性很高. 懒汉模式:能实现懒加载,但是在并 ...
- Hive开发中使用变量的两种方法
在使用hive开发数据分析代码时,经常会遇到需要改变运行参数的情况,比如select语句中对日期字段值的设定,可能不同时间想要看不同日期的数据,这就需要能动态改变日期的值.如果开发量较大.参数多的话, ...
- 区间和序列上的dp
区间上的dp状态设计最基本的形式: \(F[i]\)表示以i结尾的最优值或方案数. \(F[i][k]\)表示以i结尾附加信息为k的最优值或方案数. 当然可以有多维附加信息. 转移的话往往是枚举上一个 ...
- php中use关键词使用场景
php中use关键词使用场景,主要使用在函数内部使用外包得变量才使用得 1,这种函数使用不到外包变量 $messge="96net.com.cn"; $exam=function ...
- Codeforces1256F_Equalizing Two Strings
题意 给定两个字符串,可以任意选择s串的一段和t串的相同长度的一段进行翻转,无限次数,问能否通过翻转使得两个字符串相等. 分析 看了题解发现思路很巧妙. 无限次数的子串翻转其实就是相邻两个字符的交换. ...
- PostGIS 爆管分析之找出上游阀门(优化版)
说明 前面描述过利用postgis查找上游阀门的原理,以及代码,其实当初写完就发现又很大的优化空间,但一直没有时间去做. 最近遇到一个情况,处理60w+条管网数据时,效率太慢了,于是腾时间优化了一版. ...
- 092、部署Graylog日志系统(2019-05-16 周四)
参考https://www.cnblogs.com/CloudMan6/p/7808708.html Graylog 是与 ELK 可以相提并论的一款几种式日志管理方案,支持数据收集.检索.可视化 ...
- 一、Core授权(基于cookie)
一.Core的授权 配置 打开项目中的Startup.cs文件,找到ConfigureServices方法,我们通常在这个方法里面做依赖注入的相关配置.添加如下代码: public void Conf ...
- Web Api 接口测试工具:Swagger
前言:WebApi接口开发完毕后,交付给前端人员或手机端开发者时接口说明文档是必不可少的配套设备,如果公司流程不规范大家使用口口相传的交接方式,而且没有改进的欲望,那你可以到此为止了.Swagger是 ...