[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 ...
随机推荐
- kubernetes集群新增node
kubernetes集群要新增node,首先要配置ssh免密登陆 root@ht:/etc/ansible# ssh-copy-id 172.18.196.6 /usr/bin/ssh-copy-id ...
- 【分块打表】bzoj 3758 数数
[题目描述] Description 神犇最近闲来无事,于是就思考哲学,研究数字之美.在神犇看来,如果一个数的各位能够被分成两个集合,而且这两个集合里的数的和相等,那么这个数就是优美的(具体原因就只有 ...
- 下载整个网页的方法,包括样式、图片、和js
扒别人网站,不一定是要干邪恶的事(当然也有干的).有时候我们看到别人网站的功能很酷,想要自己试着实现一下.我们就需要扒一下这个页面,一方面可以线下修改学习,另一方面不会浪费时间在设计页面上,可以更关心 ...
- Hybris Virtualjdbc Extension
作者:Eason 编写日期:2018/07/31 联系方式:13920409462 1. Extension 说明 virtualjdbc extension 提供了虚拟JDBC驱动程序的实现. 通过 ...
- 【BZOJ1403】Divisibility Testing(数论)
题意: 思路: #include<cstdio> #include<cstdlib> #include<algorithm> #include<map> ...
- XCode 或者ITune 添加账号时,提示:This action could not be completed. 或者 Access Privileges
当遇到This action could not be completed 或者 You do not have enough access privileges for this operation ...
- 钱币兑换问题---hdu1284(完全背包)
Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. Input 每行只有一个正整数N,N小于32768. ...
- java基础 2 static关键字
2. static关键字 变量:静态变量在内存中只存在一份,只在类第一次实例化时初始化一次,同时类所有的实例都共享静态变量,可以直接同过类名 来访问他. 方法:静 ...
- Javascript标准事件模型
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6676913.html 1. 分类 IE -- 冒泡型 现代 ...
- Java8初体验(二)Stream语法详解(转)
本文转自http://ifeve.com/stream/ Java8初体验(二)Stream语法详解 感谢同事[天锦]的投稿.投稿请联系 tengfei@ifeve.com上篇文章Java8初体验(一 ...