【jzoj4845】【寻找】【线段树】
来源:互联网 发布:软件注册码破解工具 编辑:程序博客网 时间:2024/05/16 14:29
题目大意
这是个二维平面世界,平面上有n个特殊的果实,我从(0,0)点出发,希望得到尽量多的果实,但是出于某种特殊的原因,我的运动方式只有三种(假设当前我在(x,y)):
1、我可以走到(x+1,y)
2、我可以走到(x,y+1)
3、我可以走到(x+1,y+1)
现在我需要你的帮助,帮我找出我最多能够得到多少个果实。
解题思路
先按x为第一关键字排序,y为第二关键字排序,显然一个点只能走到右上方,由于已经按x排序,只要用线段树维护高度上最优值即可,区间修改单点查询。
code
#include<set>#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define LL long long#define LD double#define max(a,b) ((a>b)?a:b)#define min(a,b) ((a>b)?b:a)#define fo(i,j,k) for(int i=j;i<=k;i++)#define fd(i,j,k) for(int i=j;i>=k;i--)using namespace std;int const inf=2147483647;int const maxn=100000,maxy=1000000001;int n,cnt,pon=1,t[maxn*50+10],lson[maxn*50+10],rson[maxn*50+10];struct rec{ int x,y; friend bool operator<(rec x,rec y){ return (x.x<y.x)||((x.x==y.x)&&(x.y<y.y)); }};rec a[maxn+10];void pushtag(int pos){ lson[pos]=(!lson[pos])?(++pon):lson[pos]; t[lson[pos]]=max(t[lson[pos]],t[pos]); rson[pos]=(!rson[pos])?(++pon):rson[pos]; t[rson[pos]]=max(t[rson[pos]],t[pos]); t[pos]=0;}int qury(int pos,int l,int r,int v){ if(l!=r)pushtag(pos); else return t[pos]; int mid=(l+r)/2; if(v<=mid)return qury(lson[pos],l,mid,v); else return qury(rson[pos],mid+1,r,v);}void change(int pos,int l,int r,int ll,int rr,int v){ if(l!=r)pushtag(pos); int mid=(l+r)/2; if((l==ll)&&(r==rr)){ t[pos]=max(t[pos],v); return; }else if(rr<=mid){ change(lson[pos],l,mid,ll,rr,v); }else if(mid<ll){ change(rson[pos],mid+1,r,ll,rr,v); }else{ change(lson[pos],l,mid,ll,mid,v); change(rson[pos],mid+1,r,mid+1,rr,v); }}int main(){ freopen("find.in","r",stdin); freopen("find.out","w",stdout); scanf("%d",&n); fo(i,1,n){ int x,y;scanf("%d%d",&x,&y); if((x>=0)&&(y>=0)){ cnt++; a[cnt].x=x;a[cnt].y=y+1; } } sort(a+1,a+cnt+1); int ans=0; fo(i,1,cnt){ int tmp=qury(1,1,maxy,a[i].y)+1; ans=max(ans,tmp); change(1,1,maxy,a[i].y,maxy,tmp); } printf("%d",ans); return 0;}
0 0
- 【jzoj4845】【寻找】【线段树】
- Jzoj4845 寻找
- <线段树>寻找神格
- 【JZOJ4845】【NOIP2016提高A组集训第5场11.2】寻找
- poj 3264 线段树 寻找最大最小值 SEGMENT TREE
- 线段树寻找部分和为k的第一个位置
- CodeForces 46D 停车场 数据结构+线段树+寻找位置+维护空位+区间赋值
- 线段树小引申(寻找最近的没被标记过的点)
- 不走寻常路:寻找线段的中点
- 线段树?线段树!
- 线段树?线段树!
- 线段_线段树
- 线段_线段树
- 树寻找根节点
- 寻找
- 寻找
- 寻找
- 寻找...
- Topcoder SRM583
- sidr --为网页添加侧边滑出菜单栏
- 使用 Python 进行分布式系统协调
- 嵌入式的理解
- just a word
- 【jzoj4845】【寻找】【线段树】
- discuz使用其它单点登录
- 378_Html类的使用
- OpenCV各种函数详解#include<QDebug> qDebug() << "hello";
- NS-3教程(1):NS-3开发环境搭建
- 嵌入式系统概念
- 379_ViewStub点击事件
- (Java)LeetCode-68. Text Justification
- 380_ViewStub填充