[USACO 2017DEC] Haybale Feast
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=5142
[算法]
首先用RMQ预处理S数组的最大值
然后我们枚举右端点 , 通过二分求出合法的 , 最靠右的左端点 , 用这段区间的最大值更新答案 , 即可
时间复杂度 : O(NlogN)
[代码]
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + ;
const int MAXLOG = ;
const LL INF = 1e18; int n;
LL m;
LL value[MAXN][MAXLOG];
LL F[MAXN] , S[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline LL query(int l,int r)
{
int k = (int)((double)log(r - l + ) / log(2.0));
return max(value[l][k] , value[r - ( << k) + ][k]);
} int main()
{ read(n); read(m);
for (int i = ; i <= n; i++)
{
read(F[i]);
read(S[i]);
value[i][] = S[i];
}
for (int i = ; i <= n; i++) F[i] += F[i - ];
for (int i = ; i < MAXLOG; i++)
{
for (int j = ; j + ( << i) - <= n; j++)
{
value[j][i] = max(value[j][i - ],value[j + ( << (i - ))][i - ]);
}
}
LL ans = INF;
for (int i = ; i <= n; i++)
{
int l = , r = i , pos = -;
while (l <= r)
{
int mid = (l + r) >> ;
if (F[i] - F[mid - ] >= m)
{
pos = mid;
l = mid + ;
} else r = mid - ;
}
if (pos == -) continue;
chkmin(ans,query(pos,i));
}
printf("%lld\n",ans); return ; }
[USACO 2017DEC] Haybale Feast的更多相关文章
- BZOJ5142: [Usaco2017 Dec]Haybale Feast(双指针&set)(可线段树优化)
5142: [Usaco2017 Dec]Haybale Feast Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 182 Solved: 131[ ...
- BZOJ5142: [Usaco2017 Dec]Haybale Feast 线段树或二分答案
Description Farmer John is preparing a delicious meal for his cows! In his barn, he has NN haybales ...
- [USACO 08JAN]Haybale Guessing
Description The cows, who always have an inferiority complex about their intelligence, have a new gu ...
- [USACO 2017DEC] Barn Painting
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5141 [算法] 树形DP 时间复杂度 : O(N) [代码] #include< ...
- [USACO 2017DEC] Greedy Gift Takers
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5139 [算法] 二分答案 时间复杂度 : O(NlogN^2) [代码] #incl ...
- P4085 [USACO17DEC]Haybale Feast
我又开始水了,感觉又是一道虚假的蓝题 题意 非常好理解,自己看吧 题解 可以比较轻易的发现,如果对于一段满足和大于等于 \(m\) 的区间和其满足和大于等于 \(m\) 的子区间来说,选择子区间肯定是 ...
- Luogu4085 [USACO17DEC]Haybale Feast (线段树,单调队列)
\(10^18\)是要long long的. \(nlogn\)单调队列上维护\(logn\)线段树. #include <iostream> #include <cstdio> ...
- USACO 2015 December Contest, Gold Problem 2. Fruit Feast
Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
随机推荐
- Cow Exhibition (01背包)
"Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with G ...
- 72.spring boot讨论群【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 如果您碰到什么问题,您可以加群进行探讨,在群里有加入的都是Spring Boot志同道合的朋友: Spring Boot QQ交流群:193341 ...
- HackerRank# Wet Shark and Two Subsequences
原题地址 对于给定的两个约束条件,可以通过联立方程组直接解出子序列A的和和子序列B的和,即sum(A) = (r + s) / 2,sum(B) = (r - s) / 2,假设|A|=|B|=n 所 ...
- jQuery操作元素的class属性
今天在做一个菜单折叠插件的时候需要根据页面的url改变其class属性.jQuery操作元素的属性是非常方便的,在此记录一下: 1.给元素添加class属性: addClass(class) (1)添 ...
- 远程连接mongodb时,27017端口连接不上的解决办法
一.背景描述: 我在linux RED7上安装了mongodb,并没有修改mongodb的配置文件.然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout. ping IP ...
- php除法的知识点
php除法的知识点 $a = 7; $b = 3; $c = $a/$b; var_dump($c);//float(2.3333333333333) //整数部分+小数点+小数部分=15位 $b = ...
- Kibana 可视化监控报警插件 KAAE 的介绍与使用
https://blog.csdn.net/phachon/article/details/53424631 https://blog.csdn.net/Dragon714/article/detai ...
- scoi2018游记
day1: t1点分树 冬令营上jry讲过原题,t2启发式合并+解二次同余方程 预计100+100+0 结果t1卡内存,t2模数太大.导致调试到没有写t3 最后t1 85 t2 15 要是我会o1快速 ...
- freeswitch对媒体的处理的三种方式
一.默认方式:媒体通过freeswitch, RTP被freeswtich转发, freeswitch控制编码的协商并在协商不一致时提供语音编码转换能力, 支持录音,二次拨号等. 二.代理模式: ...
- Springmvc 前台传递参数到后台需要数据绑定
我们知道,当提交表单时,controller会把表单元素注入到command类里,但是系统注入的只能是基本类型,如int,char,String.但当我们在command类里需要复杂类型,如Integ ...