bzoj 4094: [Usaco2013 Dec]Optimal Milking
4094: [Usaco2013 Dec]Optimal Milking
Description
Input
Output
Sample Input
1
2
3
4
5
5 2
2 7
1 10
Sample Output
【样例解释】
第1天,最优方案为2+4=6 ( 方案1+3+2一样)
第2天,最优方案为7+4=11
第3天,最优方案为10+3+2=15
Source
Gold
题解:
线段树。。
没什么好说的。。
发四种情况讨论
1.两边都选
2.左选右不选
3.左不选右选
4.都不选
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=40005;
#define p1 (p<<1)
#define p2 (p<<1|1)
int n,m,i,x,y,a[N],t[N<<2][4];
long long ans;
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';
}
void pushup(int p)
{t[p][0]=t[p][1]=t[p][2]=t[p][3]=0;if(t[p1][0]!=-1&&t[p2][2]!=-1) t[p][0]=t[p1][0]+t[p2][2];if(t[p1][1]!=-1&&max(t[p2][0],t[p2][2])!=-1) t[p][0]=max(t[p][0],t[p1][1]+max(t[p2][0],t[p2][2]));if(t[p1][0]!=-1&&t[p2][3]!=-1) t[p][1]=t[p1][0]+t[p2][3];if(t[p1][1]!=-1&&max(t[p2][1],t[p2][3])!=-1) t[p][1]=max(t[p][1],t[p1][1]+max(t[p2][1],t[p2][3]));if(t[p1][2]!=-1&&t[p2][2]!=-1) t[p][2]=t[p1][2]+t[p2][2];if(t[p1][3]!=-1&&max(t[p2][0],t[p2][2])!=-1) t[p][2]=max(t[p][2],t[p1][3]+max(t[p2][0],t[p2][2]));if(t[p1][2]!=-1&&t[p2][3]!=-1) t[p][3]=t[p1][2]+t[p2][3];if(t[p1][3]!=-1&&max(t[p2][1],t[p2][3])!=-1) t[p][3]=max(t[p][3],t[p1][3]+max(t[p2][1],t[p2][3]));
}
void build(int l,int r,int p)
{if(l==r){t[p][0]=a[l];t[p][3]=0;t[p][1]=t[p][2]=-1;return;}int mid=(l+r)>>1;build(l,mid,p1);build(mid+1,r,p2);pushup(p);
}
void update(int l,int r,int x,int y,int p)
{if(l==r) {t[p][0]=y;return;}int mid=(l+r)>>1;if(x<=mid) update(l,mid,x,y,p1);else update(mid+1,r,x,y,p2);pushup(p);
}
int main()
{read(n),read(m);for(i=1;i<=n;i++) read(a[i]);build(1,n,1);while(m--){read(x),read(y);update(1,n,x,y,1);ans+=max(max(t[1][0],t[1][1]),max(t[1][2],t[1][3]));}cout<<ans;return 0;
}
转载于:https://www.cnblogs.com/lwq12138/p/5791080.html
bzoj 4094: [Usaco2013 Dec]Optimal Milking相关推荐
- bzoj 4094: [Usaco2013 Dec]Optimal Milking 线段树
→题目链接← [想说的话] 再次手误... [题解] 对于每个区间维护四种最大值 1.选左端点不选右端点 2.选右端点不选左端点 3.两个端点都选 4.两个端点都不选 然后用线段树搞一搞就好了 注意下 ...
- [bzoj4094][Usaco2013 Dec]Optimal Milking 线段树
4094: [Usaco2013 Dec]Optimal Milking Time Limit: 10 Sec Memory Limit: 128 MB [Submit][Status][Discu ...
- 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树
[BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...
- bzoj4094[Usaco2013 Dec]Optimal Milking最优挤奶
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4094 题目大意: 约翰有N 台挤奶机器,这些机器排成了一条直线,其中第i台机器工作效率是A ...
- BZOJ 4094 USACO 2013 Dec. Optimal Milking
线段树 每个节点保存4个值,both表示左右端点都取,neither表示左右端点都不取,left表示只取左端点,right表示只取右端点. 维护的特殊姿势: $cur$的$both=max(ls.l+ ...
- POJ 2112 Optimal Milking(二分+最大流)
POJ 2112 Optimal Milking 题目链接 题意:给定一些机器和奶牛,在给定距离矩阵,(不在对角线上为0的值代表不可达),每一个机器能容纳m个奶牛.问全部奶牛都能挤上奶,那么走的距离最 ...
- 【BZOJ4094】 【Usaco2013 Dec】Optimal Milking(权限题)
Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号为1 ... N,并排成一行.第i台挤奶机每天能够挤M(i)单位的牛奶 (1 &l ...
- BZOJ 1692: [Usaco2007 Dec]队列变换( 贪心 )
数据 n <= 30000 , 然后 O( n² ) 的贪心也过了..... USACO 数据是有多弱啊 = = ( ps : BZOJ 1640 和此题一模一样 , 双倍经验 ) ------ ...
- bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子(二分)
1650: [Usaco2006 Dec]River Hopscotch 跳石子 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 721 Solved: ...
最新文章
- 如何最大化利用CPU性能创作沉浸式VR体验
- 信息系统项目管理师-配置管理知识点
- 自然语言处理库——NLTK
- jar包打补丁 jar -uf_maven项目引入本地jar包的方法
- 使用Dottrace跟踪代码执行时间
- 如何做好游戏内实时语音体验
- 第4章操作系统基础第五版Aimin.rar
- insert mysql后加where,如何在MySQL Insert語句中添加where子句?
- float型数据与字节数组的转化
- 由 go orm 引发的探索
- 【SAP解决方案干货合集】满满的干货,是您了解华为云SAP解决方案的必备利器
- js(一) 三大事件 实现注册验证
- POJ 2135 Farm Tour
- Scrapy框架结合Spynner采集需进行js,ajax动态加载的网页并提取网页信息(以采集微信公众号文章列表为例)
- Linux下用ffmpeg轉PSP影片 (MP4/AVC格式)
- python爬取2017年统计用区划代码和城乡划分代码(截止2017年10月31日)
- CSR8675项目实战:BlueAg蓝牙一拖二发射器
- 用C语言写迎风飘扬的旗帜,驻村旗帜迎风飘扬
- 写博客有什么意义以及为什么?
- 【NOI2015】【BZOJ4199】品酒大会
热门文章
- PySpark︱pyspark.ml 相关模型实践
- 自然语言处理︱简述四大类文本分析中的“词向量”(文本词特征提取)
- [机器学习]朴素贝叶斯原理和基于Spark 实例
- sql server下载教程
- LeetCode 220_Contains Duplicate III
- POJ 1659 Frogs#39; Neighborhood(度序列组成)
- Debian GNU/kFreeBSD是什么
- 使用Unity开发项目的一点经验
- wraper for bootstrap3.0 + simple_form
- struts2 配置 自学练习 list jsp页输出 中文转英文首字母