hdu 4742 Pinball Game 3D(三维LIS&cdq分治&BIT维护最值)
Pinball Game 3D
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 688 Accepted Submission(s): 276
Recently, RD has found a new type of pinball game, a 3D pinball game. The 3D pinball game space can be regarded as a three dimensional coordinate system containing N balls. A ball can be considered as a point. At the beginning, RD made a shot and hit a ball.
The ball hit by RD will move and may hit another ball and the “another ball” may move and hit another another ball, etc. But once a ball hit another ball, it will disappear.
RD is skilled in this kind of game, so he is able to control every ball's moving direction. But there is a limitation: if ball A's coordinate is (x1,y1,z1) and ball B's coordinate is (x2,y2,z2), then A can hit B only if x1 <= x2 and y1 <= y2 and z1 <= z2.
Now, you should help RD to calculate the maximum number of balls that can be hit and the number of different shooting schemes that can achieve that number. Two schemes are different if the sets of hit balls are not the same. The order doesn't matter.
In each case, the first line contains one integer N indicating the number of balls.
The next N lines each contains three non-negative integer (x, y, z), indicating the coordinate of a ball.
The data satisfies T <= 3, N <= 105, 0 <= x, y, z <= 230, no two balls have the same coordinate in one case.
2
3
2 0 0
0 1 0
0 1 1
5
3 0 0
0 1 0
0 0 1
0 2 2
3 3 3
2 1
3 2HintIn the first case, RD can shoot the second ball at first and hit the third ball indirectly.
In the second case, RD can shoot the second or the third ball initially and hit the fourth ball as well as the fifth ball. Two schemes are both the best.
pid=5052" target="_blank">5052
比方我们要算[l,r]的dp值。mid=(L+r)/2如果我们已经算出了[l,mid]的dp值。我们是不是能够用[l,mid]的dp值去更新[mid+1,r]的dp值。
由于dp[i]一定是由1~i-1转移来的所以我们能够建一个树状数组维护z值为zz的最大dp(由于这题每次都是查询[1,x]整个区间所以能够用树状数组来维护最值)。当然z值是离散化后的值。然后我们两边的y排序.然后对于[mid+1,r]的每个dp我们按y值从小到大更新。先把[l,mid]中y值比自己小的插到树状数组中。
然后查询数组数组中z小于自己z的最大dp即可了。这样就能够保证树状数组中的元素x,y都是合理的然后查询的z也是合理的。然后递归处理即可了。先solve(l,mid)然后更新[mid+1,r]再solve(mid+1,r)。
当然递归的时候也能够顺便进行一些排序操作(归并排序)以提高效率。
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=100010;
const int mod=1<<30;
typedef long long ll;
struct node
{
int x,y,z;
inline bool operator <(const node& tt) const
{
if(x!=tt.x)
return x<tt.x;
if(y!=tt.y)
return y<tt.y;
return z<tt.z;
}
} po[maxn];
int dp[maxn],sy[maxn],sz[maxn],mv[maxn],ans;
int tmp[maxn<<1],ty[maxn],ptr;
ll num[maxn],nv[maxn],ansn;
bool cmp(int a,int b)//注意y必须这么排.不然可能出现y相等的时候i+1排到i前面的情况.
{
if(po[a].y!=po[b].y)
return po[a].y<po[b].y;
return a<b;
}
void update(int x,int v,ll d,int mn)
{
for(int i=x;i<=mn;i+=i&-i)
{
if(v>mv[i])
mv[i]=v,nv[i]=d;
else if(v==mv[i])
nv[i]+=d;
}
}
int qu(int x,ll &nn)
{
int ret=0;
for(int i=x;i>0;i-=i&-i)
{
if(ret<mv[i])
ret=mv[i],nn=nv[i];
else if(mv[i]==ret)
nn+=nv[i];
}
return ret;
}
void solve(int l,int r)
{
if(l==r)
{
if(dp[l]>ans)
ans=dp[l],ansn=num[l];
else if(dp[l]==ans)
ansn+=num[l];
sz[l]=po[l].z;
return;
}
int mid=(l+r)>>1,le=l,ri=mid+1,len=r-l+1,ml=mid-l+1,lim,h,i;
memmove(tmp+ptr,sy+l,len*sizeof(int));
for(i=0;i<len;i++)
if(tmp[ptr+i]<=mid)//直接把排好的序划分下去即可了。 sy[le++]=tmp[ptr+i];
else
sy[ri++]=tmp[ptr+i];
ptr+=len;
solve(l,mid);
lim=ptr,ptr-=len;
for(i=1;i<=ml;i++)
mv[i]=0;
for(i=ptr;i<lim;i++)
{
if(tmp[i]<=mid)
{
h=lower_bound(sz+l,sz+l+ml,po[tmp[i]].z)-(sz+l)+1;
update(h,dp[tmp[i]],num[tmp[i]],ml);
continue;
}
h=lower_bound(sz+l,sz+l+ml,po[tmp[i]].z)-(sz+l);
if(h>=ml||sz[l+h]>po[tmp[i]].z)
h--;
if(h>=0)
{
ll cc=0;
int tt=qu(h+1,cc)+1;
if(tt>dp[tmp[i]])
dp[tmp[i]]=tt,num[tmp[i]]=cc;
else if(tt==dp[tmp[i]]&&tt!=1)
num[tmp[i]]+=cc;
}
}
solve(mid+1,r);
merge(sz+l,sz+l+ml,sz+l+ml,sz+l+len,ty);
memmove(sz+l,ty,len*sizeof(int));
}
int main()
{
int t,n,i; scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d%d%d",&po[i].x,&po[i].y,&po[i].z);
ansn=ptr=ans=0;
sort(po+1,po+n+1);
for(i=1;i<=n;i++)
sy[i]=i,dp[i]=1,num[i]=1;
sort(sy+1,sy+n+1,cmp);
solve(1,n);
printf("%d %I64d\n",ans,ansn%mod);
}
return 0;
}
/*
送一组数据。网上好多代码都过不了这组。就是由于排序y的时候i+1排到i前面去了。导致少更新非常多
杭电数据比較水就水过去了。 1
17
2 0 0
2 1 1
1 2 1
1 0 0
0 0 1
0 2 0
0 2 2
0 1 1
2 0 1
1 2 2
0 1 0
2 0 2
2 2 2
0 1 2
1 0 2
1 1 1
0 0 2
*/
hdu 4742 Pinball Game 3D(三维LIS&cdq分治&BIT维护最值)的更多相关文章
- HDU4742----Pinball Game 3D(三维LIS、CDQ分治)
题意:三维空间内 n个小球,对应坐标(x,y,z).输出LIS的长度以及方案数. 首先可以先按x排序,先降低一维,然后 剩下y .z,在y上进行CDQ分治,按y的大小用前面的更新后面的.z方向离散化之 ...
- HDU-4742 Pinball Game 3D 三维LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意:求3维的LIS.. 用分治算法搞得,参考了cxlove的题解.. 首先按照x排序,然后每个 ...
- hdu 4742 Pinball Game 3D 分治+树状数组
离散化x然后用树状数组解决,排序y然后分治解决,z在分治的时候排序解决. 具体:先对y排序,solve(l,r)分成solve(l,mid),solve(mid+1,r), 然后因为是按照y排序,所以 ...
- cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )
hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...
- HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5618 Jam's problem again(三维偏序,CDQ分治,树状数组,线段树)
Jam's problem again Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu5618 (三维偏序,cdq分治)
给定空间中的n个点,问每个点有多少个点小于等于自己. 先来分析简单的二维的情况,那么只要将x坐标排序,那么这样的问题就可以划分为两个子问题,,这样的分治有一个特点,即前一个子问题的解决是独立的,而后一 ...
- 二维LIS(CDQ分治)
题目描述 给定一个长度为N的序列S,S的每个元素pi是一个二元组(xi,yi),定义pi<pj当且仅当xi<xj并且yi<yj,求S的最长上升子序列长度 输入格式 第一行一个N,表示 ...
- HDU 5618:Jam's problem again(CDQ分治+树状数组处理三维偏序)
http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意:…… 思路:和NEUOJ那题一样的.重新写了遍理解了一下,算作处理三维偏序的模板了. #includ ...
随机推荐
- 21.多源最短路(floyd算法)
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 已知n个点(n<=100),给你n*n的方阵,a[i,j] ...
- python开发_zlib_完整版_博主推荐
''' python中的zlib模块提供了压缩和解压缩的方法 实现功能: 读取一个文件的内容,然后把该文件的内容以字符串的形式返回 然后对返回回来的字符串进行压缩处理,然后写入到另一个文件中 同时,也 ...
- HDU 5670 Machine 水题
Machine 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5670 Description There is a machine with m(2 ...
- 普及向 ZKW线段树!
啊,是否疲倦了现在的线段树 太弱,还递归! 那我们就欢乐的学习另外一种神奇的线段树吧!(雾 他叫做zkw线段树 这个数据结构灰常好写(虽然线段树本身也特别好写……) 速度快(貌似只在单点更新方面比 ...
- intellj远程调试设置
场景:本地intelllij想远程调试服务器A,服务器A上起得是resin服务 步骤: 1.登陆服务器A,给resin添加启动参数. 方法一:修改resin.xml,修改完后重启resin服务器 在r ...
- C# MATLAB混合编程
我附带把matlab配置过程也给大家上传上来.[转载]终于学会C#调用matlab函数了,原来这么简单(也可以下载附件查看)自己的配置: (1)Microsoft Visual Studio 2005 ...
- ES6系列汇总
汇 总 第一节:什么是ES6?新手该如何理解 第二节:ES6新增了let关键字,干嘛用的? 第三节:ES6中另一个不得不说的关键字const 第四节:教你如何快速让浏览器兼容ES6特性 第五节:一个令 ...
- ELM322 - OBD (VPW) to RS232 Interpreter (v2.0)
http://elmelectronics.com/DSheets/ELM322DS.pdf
- EntityFramework:迁移工具入门
背景 刚毕业做项目的时候,没有用“迁移”这个概念,系统发布和更新的过程让人非常痛苦,在学习 Ruby On Rails 的过程解除了“迁移”,以后的所有项目都会先确定好“迁移”的方案,本文介绍一下En ...
- 将matlab的figure保存为pdf,避免图片太大缺失
有时画的matlab图太大,或者有太多的子图,导致图太宽,如果直接保存成pdf的话,会导致左右边丢失,显示不下.一个有效又简单的办法是: 1.在matlab figure里面,Edit -> ...