hdu 6012 Lotus and Horticulture(贪心)
来源:互联网 发布:mysql修复数据表 编辑:程序博客网 时间:2024/05/30 22:53
Lotus and Horticulture
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 585 Accepted Submission(s): 188
Total Submission(s): 585 Accepted Submission(s): 188
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 then 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 provideai units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide thebi units of research value; temperatures below the lower limit of the appropriate temperature, can provideci units of research value.
Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values ofa ,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.__
Lotus placed all of the
Each plant has an optimal growth temperature range of
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
Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of
__NOTICE: the temperature can be any real number.__
Input
The input includes multiple test cases. The first line contains a single integerT , the number of test cases.
The first line of each test case contains a single integern∈[1,50000] , the number of potted plants.
The nextn line, each line contains five integers li,ri,ai,bi,ci∈[1,109] .
The first line of each test case contains a single integer
The next
Output
For each test case, print one line of one single integer presenting the answer.
Sample Input
155 8 16 20 1210 16 3 13 138 11 13 1 117 9 6 17 52 11 20 8 5
Sample Output
83
Source
BestCoder Round #91
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6012
题目大意:一个温室种花,每种花都有一个适合生长的温度区间,低于提供ci的价值,等于提供ai价值,大于提供bi价值,问最大价值总和;
题目思路:这是一种很经典的贪心,把每个区间分成左右两个端点,记录每个端点的左右,所属区间,和大小。按大小排序(若大小相同,则左端点排前面)。如此排序,易得初始情况是所有花都在低于的温度下成长,然后遍历端点,左端点加ai-ci,右端点加bi-ai;
易错点: 这种贪心易错在端点相同时的考量;如这题:
端点相同时,把同属左端点的的值优先考量,再考量同属右端点。
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=50000+100;int a[maxn],b[maxn],c[maxn];struct node{ int l,id,f; bool operator<(const node&p)const { if(l!=p.l) return l<p.l; return f>p.f; }} A[maxn*2];int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); ll ans=0,res=0; int l,r; int len=0; for(int i=0; i<n; i++) { scanf("%d%d%d%d%d",&l,&r,&a[i],&b[i],&c[i]); A[len].l=l; A[len].id=i; A[len++].f=1; res+=c[i]; A[len].l=r; A[len].id=i; A[len++].f=-1; } sort(A,A+len); ans=res; for(int i=0; i<len; i++) { l=i; while(A[i+1].l==A[i].l&&A[i+1].f==A[i].f)i++; for(int j=l;j<=i;j++) { int id=A[j].id; if(A[j].f==1) { res+=a[id]-c[id]; } else { res+=b[id]-a[id]; } } ans=max(ans,res); } printf("%I64d\n",ans); } return 0;}
2 0
- hdu 6012 Lotus and Horticulture(贪心)
- Lotus and Horticulture(贪心)
- HDU 6012 Lotus and Horticulture
- hdu 6012 Lotus and Horticulture
- HDU 6012 Lotus and Horticulture
- hdu 6012 Lotus and Horticulture
- Hdu 6012 Lotus and Horticulture【思维】
- [hdu 6012Lotus and Horticulture]优先队列
- 【HDU 6012 Lotus and Horticulture】+ 思维 + map
- HDU 6012 Lotus and Horticulture 离散化
- HDOJ 6012 Lotus and Horticulture
- hdu 6012 Lotus and Horticulture 思维+前缀和处理
- BestCoder Round #91 1001 (HDU 6011 Lotus and Characters) 1002 (HDU 6012 Lotus and Horticulture)
- 【HDOJ】【BC91】6012 Lotus and Horticulture
- ***【杭电6012】Lotus and Horticulture
- Lotus and Horticulture
- Lotus and Horticulture
- HDU 6012 Lotus and Horticulture [离散化+前缀和处理]【思维】
- File操作(4)-----文件复制(一)
- 注解Annotation的IoC:从@Autowired到@Componen
- Purpose: xp_cmdshell 扩展存储过程的使用
- Eclipse:Could not create the view:解决办法
- Leetcode 436. Find Right Interval
- hdu 6012 Lotus and Horticulture(贪心)
- Python(1):HelloWorld
- 股票入门基础知识43:利用多时间框架分析
- 欢迎使用CSDN-markdown编辑器
- 浅学CMake
- 欢迎使用CSDN-markdown编辑器
- 自动导入上传数据的注意事项
- IE6中盒子绝对定位不起效果的解决方法
- python3.5 安装scrapy