[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 ...
随机推荐
- json拼接含字符串变量的问题
json键值对,当值为字符串变量时,极易搞错,拼接务必注意.String str="文字信息";String json="{\"msg\":\&quo ...
- Ubuntu安装sublime Text 3并配置可以输入中文
使用Ubuntu系统后,想找一个顺手的编辑器,sublime作为我的首选编辑器,在安装和配置可输入中文时遇到各种个样的问题,总结一些: 1:问题: 我的系统是Ubuntu 18.04 LTS,尝试多次 ...
- Washing Clothes(poj 3211)
大体题意:有n件衣服,m种颜色,某人和他的女炮一起洗衣服,必须一种颜色洗完,才能洗另一种颜色,每件衣服都有时间,那个人洗都一样,问最少用时. poj万恶的C++和G++,害得我CE了三次 /* 背包啊 ...
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]
传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...
- 【转】php 之 array_filter、array_walk、array_map的区别
[转]php 之 array_filter.array_walk.array_map的区别 原文:https://blog.csdn.net/csdnzhangyiwei/article/detail ...
- c/s程序版本自动升级的问题,如何判断client端版本号是否最新,然后从指定ftp服务器down
c/s程序版本自动升级的问题,如何判断client端版本号是否最新,然后从指定ftp服务器down http://blog.csdn.net/delphizhou/article/details/30 ...
- 基于Hexo + Git + Nginx的博客发布
进过上一篇<树莓派搭建私人服务器>,我们已经有一个私人服务器了,现在需要做点什么实际事情了,先搭一个博客分享自己的经验吧. 相关文章:1.<树莓派搭建私人服务器>(http:/ ...
- CentOS7 设置系统时间
在CentOS 6版本,时间设置有date.hwclock命令, 硬件时钟和系统时钟 (1) 硬件时钟 RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会 ...
- Deepin-安装git
sudo apt-get install git 命令介绍(安装软件):apt-get install 命令介绍(Debian系列以管理员运行的前缀):sudo
- Guice 学习(八)AOP (面向切面的编程)
Guice的AOP还是非常弱的.眼下只支持方法级别上的,另外灵活性也不是非常高. 看例如以下演示样例: Guice支持AOP的条件是: 类必须是public或者package (default) 类不 ...