洛谷 P3957 跳房子
https://www.luogu.org/problemnew/show/P3957
错误记录:1.没开longlong 2. -inf不够小
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
#define int ll
typedef pair<int,int> pii;
int n,d,K;
pii p[];
int qq[],ql,qr;
int an[];
//an[i]表示i格子最大得分
//an[i]=max{an[j]}+s[i],i-r<=j<=i-l
bool judge(int ttt)
{
int l=max(1ll,d-ttt),r=d+ttt;
ql=;qr=;
int ans=-0x3f3f3f3f3f3f3f3f,L,R,i;
an[]=;
for(i=,L=,R=-;i<=n;i++)
{
while(R+<i&&p[R+].fi<=p[i].fi-l)
{
++R;
while(ql<=qr&&an[qq[qr]]<=an[R]) --qr;
qq[++qr]=R;
}
while(L<i&&p[L].fi<p[i].fi-r)
{
if(qq[ql]==L) ++ql;
++L;
}
an[i]=ql<=qr?an[qq[ql]]+p[i].se:-0x3f3f3f3f3f3f3f3f;
ans=max(ans,an[i]);
}
return ans>=K;
}
signed main()
{
int nn,x,y,i;
scanf("%lld%lld%lld",&nn,&d,&K);
for(i=;i<=nn;i++)
{
scanf("%lld%lld",&x,&y);
if(!n||x!=p[n].fi) p[++n].fi=x,p[n].se=y;
else p[n].se=max(p[n].se,y);
}
int t=;
for(i=;i<=n;i++)
if(p[i].se>)
t+=p[i].se;
if(t<K)
{
puts("-1");
return ;
}
int l=,r=1e10,mid;
while(l!=r)
{
mid=l+((r-l)>>);
if(judge(mid)) r=mid;
else l=mid+;
}
printf("%lld",l);
return ;
}
洛谷 P3957 跳房子的更多相关文章
- 洛谷P3957 跳房子(Noip2017普及组 T4)
今天我们的考试就考到了这道题,在考场上就压根没有思路,我知道它是一道dp的题,但因为太弱还是写不出来. 下来评讲的时候知道了一些思路,是dp加上二分查找的方式,还能够用单调队列优化. 但看了网上的许多 ...
- 洛谷 P3957 跳房子 —— 二分答案+单调队列优化DP
题目:https://www.luogu.org/problemnew/show/P3957 先二分一个 g,然后判断: 由于转移的范围是一个区间,也就是滑动窗口,所以单调队列优化: 可以先令队尾为 ...
- 洛谷P3957 跳房子 题解 二分答案/DP/RMQ
题目链接:https://www.luogu.org/problem/P3957 这道题目我用到了如下算法: 线段树求区间最大值: 二分答案: DP求每一次枚举答案g时是否能够找到 \(\ge k\) ...
- 洛谷P3957 跳房子
普及组的题.....填坑来了. 当年的我一眼二分+DP,现在都佩服起自己来了...... 然后我们就写个二分,在check里面写单调队列优化DP即可. 然后就A了...... #include < ...
- 2018.09.26洛谷P3957 跳房子(二分+单调队列优化dp)
传送门 表示去年考普及组的时候失了智,现在看来并不是很难啊. 直接二分答案然后单调队列优化dp检验就行了. 注意入队和出队的条件. 代码: #include<bits/stdc++.h> ...
- 洛谷P3957:跳房子——题解
https://www.luogu.org/problem/P3957 沉迷普及组题无法自拔. 显然二分答案,然后里面套个dp,$f[i]$表示跳到第$i$个格子的最大得分,复杂度$O(n^2logn ...
- 【洛谷P3957】跳房子
题目大意:给定一个数轴和 N 个点,点有点权,现从 0 位置出发,初始时每次只能走 d 的距离,可以在数轴上任意位置停下,此时,会得到一个点权和.现允许支付 x 的费用,使得每次可以走的距离为一个范围 ...
- 洛谷P3975 跳房子 [DP,单调队列优化,二分答案]
题目传送门 跳房子 题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 n 个格子,这些格子都在同一 ...
- 洛谷luogu3957跳房子(单调队列优化)
QwQ被普及组的题折磨的死去活来. 硬是卡线段树,没卡过QwQ oi生涯,第一道正经的单调队列dp题 进入正题 题目大意: 其中\(n \le 500000\) 看到这个题的第一感觉就是二分金币数 很 ...
随机推荐
- 分布式版本控制系统—git命令
一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...
- Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses —— DP(01背包)
题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable ...
- Chapter 3 Shared Assemblies and Strongly Named Assemblies
As time marches on,MS developers and control developer modify their code:they fix bugs,patch securit ...
- TP框架中的多种方法代码(C,G,L,T,I,N,D,M,A,R,B,U,W,S,F,E)
C方法 function C($name=null, $value=null,$default=null) { static $_config = array(); // 无参数时获取所有 if (e ...
- org.jetbrains.android.uipreview.RenderingException: Failed to load the LayoutLib: com/android/layoutlib/bridge/Bridge : Unsupported major.minor version 52.0
在Android Studio使用的时候,突然发现Preview功能不能用了,报了一个错,错误如下 org.jetbrains.android.uipreview.RenderingException ...
- python multiprocessing多进程应用
multiprocessing包是Python中的多进程管理包,可以利用multiprocessing.Process对象来创建进程,Process对象拥有is_alive().join([timeo ...
- php之上传图片及传数据到mysql
index.html <form action="php.php" method="post" enctype="multipart/form- ...
- bzoj 3771 Triple —— FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3771 令多项式的系数是方案数,次数是值: 设 a(x) 为一个物品的多项式,即 a[w[i] ...
- 21.java方法详解
public class MethondTest07{ //入口 public static void main(String[] args){ A.m1(); //error:若方法名字的前面什么都 ...
- opencv 笔记
http://docs.opencv.org/ opencv 2.x API opencv包含以下模块 core 基本数据机构 imgproc 图像处理方法 video 视频处理方法 ...