[ABC266Ex] Snuke Panic (2D)
Problem Statement
Takahashi is trying to catch many Snuke.
There are some pits in a two-dimensional coordinate plane, connected to Snuke's nest.
Now, $N$ Snuke will appear from the pits. It is known that the $i$-th Snuke will appear from the pit at coordinates $(X_i,Y_i)$ at time $T_i$, and its size is $A_i$.
Takahashi is at coordinates $(0,0)$ at time $0$ and can do the following two kinds of moves.
- Move at a speed of at most $1$ in the $x$-direction (positive or negative).
- Move at a speed of at most $1$ in the positive $y$-direction.
Moving in the negative $y$-direction is not allowed.
He can catch a Snuke appearing from a pit if and only if he is at the coordinates of that pit exactly when it appears.
The time it takes to catch a Snuke is negligible.
Find the maximum sum of the sizes of Snuke that Takahashi can catch by moving optimally.
Constraints
- $1 \leq N \leq 10^5$
- $1 \leq T_i \leq 10^9$
- $0 \leq X_i,Y_i \leq 10^9$
- $1 \leq A_i \leq 10^9$
- The triples $(T_i,X_i,Y_i)$ are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$
$T_1$ $X_1$ $Y_1$ $A_1$
$T_2$ $X_2$ $Y_2$ $A_2$
$\vdots$
$T_N$ $X_N$ $Y_N$ $A_N$
Output
Print the answer as an integer.
Sample Input 1
3
1 0 0 100
3 2 1 10
5 3 1 1
Sample Output 1
101
The optimal strategy is as follows.
- Wait at coordinates $(0,0)$ to catch the first Snuke at time $1$.
- Go to coordinates $(3,1)$ to catch the third Snuke at time $5$.
It is impossible to catch both the first and second Snuke, so this is the best he can.
Sample Input 2
2
100 0 1 1
200 1 0 10
Sample Output 2
10
Moving in the negative $y$-direction is not allowed, so he cannot catch the first Snuke and then the second.
Sample Input 3
10
797829355 595605750 185676190 353195922
913575467 388876063 395940406 533206504
810900084 201398242 159760440 87027328
889089200 220046203 85488350 325976483
277429832 161055688 73308100 940778720
927999455 429014248 477195779 174616807
673419335 415891345 81019893 286986530
989248231 147792453 417536200 219371588
909664305 22150727 414107912 317441890
988670052 140275628 468278658 67181740
考虑 dp,定义 \(dp_{i}\) 为到达点 \(i\) 时的最大得分。明显 dp 无环。
满足以下条件时,\(dp_i\) 可以从 \(dp_j\) 转移.
- \(t_j<t_i\)
- \(y_j<y_i\)
- \(|x_i-x_j|+y_i-y_j\le t_i-t_j\)(路程差要小于时间差)
然后会发现,若条件 3 满足,条件 1 也满足。
然后把条件 3 的绝对值拆开,移项。
- \(y_j<y_i\)
- \(t_j-x_j-y_j\le t_i-x_i-y_i\)
- \(t_j+x_j-y_j\le t_i+x_i-y_i\)
那么就是一个三维偏序问题。把所有点按 \(y\) 排序,然后第二维第三维用一个树状数组套线段树维护就行了。注意将从 \(0\) 都到不了的点清掉。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long LL;
int n,x,y,t,aaa,lshc[N],lshb[N],rt[N],lc[N*200],rc[N*200],idx;
LL k,ans,tr[N*200];
struct node{
int a,b,c,d;
bool operator<(const node&n)const{
if(a!=n.a)
return a<n.a;
if(b!=n.b)
return b<n.b;
return c<n.c;
}
}a[N];
void xiugai(int&o,int l,int r,int x,LL z)
{
if(!o)
o=++idx;
if(l==r)
{
tr[o]=max(tr[o],z);
return;
}
int md=l+r>>1;
if(md>=x)
xiugai(lc[o],l,md,x,z);
else
xiugai(rc[o],md+1,r,x,z);
tr[o]=max(tr[lc[o]],tr[rc[o]]);
}
LL query(int o,int l,int r,int x,int y)
{
if(!o)
return 0;
if(x<=l&&r<=y)
return tr[o];
int md=l+r>>1;
LL ans=0;
if(md>=x)
ans=max(ans,query(lc[o],l,md,x,y));
if(md<y)
ans=max(ans,query(rc[o],md+1,r,x,y));
return ans;
}
void update(int x,int y,LL z)
{
for(;x<=n;x+=x&-x)
xiugai(rt[x],1,n,y,z);
}
LL ask(int x,int y)
{
LL ans=0;
for(;x;x-=x&-x)
ans=max(ans,query(rt[x],1,n,1,y));
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d%d",&t,&x,&y,&aaa);
if(t-x-y<0||x+t-y<0)
{
--i,--n;
continue;
}
a[i]=(node){y,t-x-y,x+t-y,aaa};
lshb[i]=t-x-y;
lshc[i]=x+t-y;
}
for(int i=1;i<=n;i++)
rt[i]=++idx;
sort(a+1,a+n+1);
sort(lshb+1,lshb+n+1);
sort(lshc+1,lshc+n+1);
for(int i=1;i<=n;i++)
{
// printf("%d\n",i);
a[i].b=lower_bound(lshb+1,lshb+n+1,a[i].b)-lshb;
a[i].c=lower_bound(lshc+1,lshc+n+1,a[i].c)-lshc;
}
for(int i=1;i<=n;i++)
{
// puts("hjhyyds");
// printf("%d %d %d\n",a[i].b,a[i].c,a[i].d);
k=ask(a[i].b,a[i].c)+a[i].d;
update(a[i].b,a[i].c,k);
ans=max(ans,k);
}
printf("%lld",ans);
}
[ABC266Ex] Snuke Panic (2D)的更多相关文章
- 2D、3D形变
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #a5b2b9 } span.Apple-tab-span { ...
- CSS 3学习——transform 2D转换
首先声明一点,transform属性不为none的元素是它的定位子元素(绝对定位和固定定位)的包含块,而且对内创建一个新的层叠上下文. 注意:可以通过 transform-box 属性指定元素的那个盒 ...
- UWP简单示例(三):快速开发2D游戏引擎
准备 IDE:VisualStudio 2015 Language:VB.NET/C# 图形API:Win2D MSDN教程:UWP游戏开发 游戏开发涉及哪些技术? 游戏开发是一门复杂的艺术,编码方面 ...
- 赠书:HTML5 Canvas 2d 编程必读的两本经典
赠书:HTML5 Canvas 2d 编程必读的两本经典 这两年多一直在和HTML5 Canvas 打交道,也带领团队开发了世界首款基于HTML5 Canvas 的演示文档工具---AxeSlide( ...
- egret3D与2D混合开发,画布尺寸不一致的问题
egret3d的GUI目前还没有,在做3d游戏的时候没有UI可用,只能使用egret2d的EUI组件库,egret3d与egret2d混合开发,canvas3d的大小与位置与canvas2d并没有重合 ...
- 一段良好的程序永远不应该发生panic异常
panic来自被调函数的信号,表示发生了某个已知的bug.一段良好的程序永远不应该发生panic异常 对于大部分程序而言,永远无法保证能够成功运行,因为错误原因往往超出程序员的控制范围.任何进行io操 ...
- IOS 2D游戏开发框架 SpriteKit-->续(创建敌对精灵)
这次包括之后讲的spritekit 我都会围绕一个案例来说,这个案例就是一个简单的2d飞机大战游戏,今天这里我讲创建敌对精灵,就是敌对飞机,敌对飞机不停的被刷新到屏幕上.....当然这里涉及到的类其实 ...
- 2D动画的制作
通过css3的transform transition可以实现平移,旋转,缩放,拉伸等效果 1.缩放 -webkit-transform: scale(1); -moz-transform: sca ...
- 2D banner
1.这是我第一次发博客咯!看到本文章后不喜勿喷,有什么需要改进的地方请多多指教! 2.今天和大家分享一下2D banner,代码如下,注释都有.因为本地测试和上传到博客环境不太一样,样式变化比较大,样 ...
- 地图四叉树一般用在GIS中,在游戏寻路中2D游戏中一般用2维数组就够了
地图四叉树一般用在GIS中,在游戏寻路中2D游戏中一般用2维数组就够了 四叉树对于区域查询,效率比较高. 原理图
随机推荐
- Python字符串操作函数split()和join()
字符串拆分 在python中有切片(Slice)操作符,可以对字符串进行截取,还提供了split()函数可以将一个 字符串分裂成多个字符串组成的列表.在使用split()函数来拆分字符串之前,我们先来 ...
- 吃透单调栈(2)——解两道Hard题:接雨水、柱状图中最大的矩形问题
怎么想到要用单调栈的? 这类题目的数据通常是一维数组,要寻找任一个元素的右边或者左边第一个比自己大或者小的元素的位置(寻找边界),此时我们就要想到可以用单调栈了. 42. 接雨水 这道题就是要求解每一 ...
- WPF学习:Slider — 冒泡显示值
想做一个下图所示的Slider,以冒泡的方式显示其Value值,该怎么做呢? 功能要求,当鼠标放在滑块上的时候,冒"泡"显示值:当滑块移动的时候,"泡"跟随移动 ...
- TypeScript中Class基础使用
TypeScript是一种静态类型的JavaScript超集,它提供了许多增强的功能,其中之一就是对面向对象编程的支持.在TypeScript中,我们可以使用Class来定义类,这使得我们能够更加结构 ...
- Linux挂载新磁盘
Linux挂载新磁盘 1. 查看磁盘 # df -lh # 查看磁盘占用情况,同时可以查看已挂载的磁盘及其挂载位置 # fdisk -l # 查看所有的磁盘分区 图中 /dev/sdb 下无分区信息, ...
- 第一次git上传的完整流程
第一次git上传的完整流程 使用git简单命令上传代码push到远程仓库 + 简单介绍了一个.git文件结构. 代码上传到gitee和github流程一样的,不过你上传到github可能网不行失败,所 ...
- OSPF路由 与 ISIS路由 与路由学习对比
转载请注明出处: 1.OSPF 路由学习规律 OSPF使用链路状态数据库(Link State Database)来存储网络拓扑信息.每个OSPF路由器通过交换链路状态更新(Link State Up ...
- Ubuntu18.04环境下安装redis 6.2.0,配置文件的部分参数说明
环境是win11的Linux子系统Ubuntu-18.04,安装方式是源码安装,也可以用apt安装(见本文最后参考资料),用的用户是默认用户(所以一些关键命令要注意用sudo,不用会报错) 安装: j ...
- 2D物理引擎 Box2D for javascript Games 第六章 关节和马达
2D物理引擎 Box2D for javascript Games 第六章 关节和马达 关节和马达 到现在你所见到的所有类型的刚体有着一些共同点:它们都是自由的并且在除碰撞的请款之外,彼此没有依赖. ...
- mybatis plus很好,但是我被它坑了!
作者今天在开发一个后台发送消息的功能时,由于需要给多个用户发送消息,于是使用了 mybatis plus 提供的 saveBatch() 方法,在测试环境测试通过上预发布后,测试反应发送消息接口很慢得 ...