[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 ...
随机推荐
- Go循环语句
package main import ( "fmt" "strconv" "os" "bufio" ) //for的条 ...
- Codeforces474E - Pillars
Portal Description 给出一个\(n(n\leq10^5)\)的正整数序列\(\{a_n\}(a_i\leq10^{15})\)和正整数\(d(d\leq10^9)\),求\(\{a_ ...
- 【dfs】codeforces Journey
http://codeforces.com/contest/839/problem/C [AC] #include<iostream> #include<cstdio> #in ...
- 两行代码搞定UI主流框架
XCNavTab XCNavTab适用于快速搭建NavigationController和TabBarController相结合的框架 https://github.com/xiaocaiabc/XC ...
- 数据库中的DDL/DML/DCL解释(转)
DDL is Data Definition Language statements. Some examples:数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 1.CREATE - ...
- Spring基于注解的配置概述
以下内容引用自http://wiki.jikexueyuan.com/project/spring/annotation-based-configuration.html: 从Spring 2.5开始 ...
- C++:vector中的resize()函数 VS reserve()函数
http://www.cnblogs.com/biyeymyhjob/archive/2013/05/11/3072893.html
- 碰撞检測之Sphere-Box检測
检測思路 首先要做的是将Box转为AABB,然后推断圆心是否在Box内.用的就是之前的SAT 假设圆心在Box内,肯定相交, 假设不在圆心内.则有四种情况,与顶点相交,与楞相交,与面相交,这里的确定也 ...
- CodeForces 404 Marathon ( 浮点数取模 -- 模拟 )
B. Marathon time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- CF 234 C Weather(粗暴方法)
C. Color Stripe time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...