hdu6012Lotus and Horticulture离散化线性取最大值
来源:互联网 发布:js 获取input的value 编辑:程序博客网 时间:2024/06/15 12:36
题意简单的说,每个植物的在不同时间段有三个价值,分为a,b,c。
找到最佳时间的最大价值,只需要求出价值的值。
可以把这三个值,类似于哈希用map把对应的时间边界和价值数关联。
那么循环便利一遍,map是有自动排序的,从小的时间点循环到最大的时间点。
其中得到的最值便为最大价值。
离散化,因为l到r的时间段内,时间点可取任意实数,也就是可以取0.5,那么必须要把
r+1和下次会碰到的另一个植物的l时间点分开,所以需要离散化。变为r*2+1 和 l*2
#include <bits/stdc++.h>using namespace std;int main(){ int T; scanf("%d",&T); while(T--) { map<int ,long long> A; int n; scanf("%d",&n); for(int i=0;i<n;i++){ int l,r,a,b,c; scanf("%d%d%d%d%d",&l,&r,&a,&b,&c); A[0]+=c; A[l*2]+=a-c; A[r*2+1]+=b-a; } long long ans=0; long long cnt=0; for(map<int,long long>::iterator it=A.begin();it!=A.end();it++){ cnt+=(it->second); ans=max(ans,cnt); } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- hdu6012Lotus and Horticulture离散化线性取最大值
- HDU 6012 Lotus and Horticulture 离散化
- HDU 6012 Lotus and Horticulture [离散化+前缀和处理]【思维】
- hdu6012(bestcoder 91) Lotus and Horticulture(离散化+前缀和)
- Lotus and Horticulture
- Lotus and Horticulture
- HDU6012 Lotus and Horticulture 扫描
- HDU 6012 Lotus and Horticulture
- BestCoder#91Lotus and Horticulture
- HDOJ 6012 Lotus and Horticulture
- hdu 6012 Lotus and Horticulture
- HDU 6012 Lotus and Horticulture
- Lotus and Horticulture(贪心)
- hdu 6012 Lotus and Horticulture
- Hdu 6012 Lotus and Horticulture【思维】
- 【HDOJ】【BC91】6012 Lotus and Horticulture
- [hdu 6012Lotus and Horticulture]优先队列
- 【HDU 6012 Lotus and Horticulture】+ 思维 + map
- 使用MIB来监控你的应用(tuxedo mib)
- 属性驱动封装
- Struts2+Spring+Hibernate+Jbpm技术实现Oa(Office Automation)办公系统第一天框架搭建
- dns2
- 【SpringMVC-004】idea创建SpringMVC项目傻瓜教程-REST简介
- hdu6012Lotus and Horticulture离散化线性取最大值
- Ubuntu 16.04+OpenFace的配置和简单人脸检测
- Java并发编程:线程池的使用
- Superchaeger注册码(激活码)
- Shell 要点记录
- Unity中Socket和多线程导致Editor和程序卡住解决
- OpenGL学习——入门篇 第二章 基础实例2-3 RGBA颜色和索引色
- No sql_connection parameter is established
- 常见类---BigInteger类