HDU-4742 Pinball Game 3D 三维LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4742
题意:求3维的LIS。。
用分治算法搞得,参考了cxlove的题解。。
首先按照x排序,然后每个三元组一个编号1-n。接下来只要考虑y和z的值,假设[l,mid]区间已经求好,那么我们对[l,r]区间按照y排序,更新[mid+1,r]区间的最优值时,只要考虑z值了,用树状数组维护z的最长LIS,遇到[mid+1,r]区间的就更新。
//STATUS:C++_AC_1750MS_5348KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
int x,y,z,id;
bool operator <(const Node& a)const{
return x!=a.x?x<a.x:(y!=a.y?y<a.y:z<a.z);
}
}a[N],b[N];
pii f[N],bit[N];
int z[N];
int T,n,m; #define lowbit(x) (x&-x) inline void update(pii& a,pii& b)
{
if(b.first>a.first)a=b;
else if(b.first==a.first){
a.second+=b.second;
}
} inline void add(int x,pii& b)
{
for(;x<=m;x+=lowbit(x)){
update(bit[x],b);
}
} inline pii query(int x)
{
pii ret=make_pair(,);
for(;x>;x-=lowbit(x)){
update(ret,bit[x]);
}
return ret;
} inline void clear(int x)
{
for(;x<=m;x+=lowbit(x)){
bit[x]=make_pair(,);
}
} void solve(int l,int r)
{
if(l==r)return;
int i,j,k,mid,cnt=;
mid=(l+r)>>;
solve(l,mid);
for(i=l;i<=r;i++){
b[cnt]=a[i];
b[cnt++].x=;
}
sort(b,b+cnt);
for(i=;i<cnt;i++){
if(b[i].id<=mid){
add(b[i].z,f[b[i].id]);
}
else {
pii t=query(b[i].z);
t.first++;
update(f[b[i].id],t);
}
}
for(i=;i<cnt;i++){
if(b[i].id<=mid)
clear(b[i].z);
}
solve(mid+,r);
} int main()
{
// freopen("in.txt","r",stdin);
int i,j;
pii ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++){
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
z[i]=a[i].z;
} sort(a,a+n);
sort(z,z+n);
m=unique(z,z+n)-z;
for(i=;i<n;i++){
f[i]=make_pair(,);
a[i].id=i;
a[i].z=lower_bound(z,z+m,a[i].z)-z+;
}
solve(,n-);
ans=make_pair(,);
for(i=;i<n;i++){
update(ans,f[i]);
} printf("%d %d\n",ans.first,ans.second);
}
return ;
}
HDU-4742 Pinball Game 3D 三维LIS的更多相关文章
- 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) ...
- 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) ...
- HDU4742 CDQ分治,三维LIS
HDU4742 CDQ分治,三维LIS 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意: 每个球都有三个属性值x,y,z,要求最长的lis的 ...
- three.js 3d三维网页代码加密的实现方法
http://www.jiamisoft.com/blog/17827-three-js-3dsanweiwangyejiami.html https://www.html5tricks.com/ta ...
- HDU4742----Pinball Game 3D(三维LIS、CDQ分治)
题意:三维空间内 n个小球,对应坐标(x,y,z).输出LIS的长度以及方案数. 首先可以先按x排序,先降低一维,然后 剩下y .z,在y上进行CDQ分治,按y的大小用前面的更新后面的.z方向离散化之 ...
- HDU 5087 (线性DP+次大LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目大意:求次大LIS的长度.注意两个长度相同的LIS大小比较,下标和大的LIS较大. 解题思 ...
- HDU 1885 Key Task(三维BFS)
题目链接 题意 : 出口不止一个,一共有四种颜色不同的门由大写字母表示,而钥匙则是对应的小写字母,当你走到门前边的位置时,如果你已经走过相应的钥匙的位置这个门就可以走,只要获得一把钥匙就可以开所有同颜 ...
随机推荐
- linux kernel启动流程
linux kernel启动是从./init/main.c中开始的,其大概流程是: 1. 调用start_kernel()函数: 2. start_kernel()调用rest_init()函数: 3 ...
- ActiveMQ之消息指针
消息指针(Message cursor)是activeMQ里一个非常重要的核心类,它是提供某种优化消息存储的方法.消息中间件的实现一般都是当消费者准备好消费消息的时候,它会从持久化存储中一批一批的读取 ...
- hibernate--关联映射(多对一,一对一)
多对一 关联映射 --- many-to-one 场景:用户和组:从用户角度来,多个用户属于一个组(多对一 关联) 使用hibernate开发的思路:先建立对象模型(领域模型),把实体抽取出来. 目前 ...
- ExtJs自学教程(1):一切从API开始
题 记 该系列文章不侧重全方位的去介绍ExtJs的使用,只是侧重于解决ExtJs问题的思考方法.写的人不用长篇大论,学的人则能够自立更生.l 学习的人只要有一些CSS的javascript的基础知识 ...
- Anchor和Dock的区别
Dock的Bottom,整个控件填充下半部分,控件会被横向拉长 Anchor,仅仅是控件固定在下方,位置不会发生移动,自动锚定了此控件和父容器的底部的间隔 Anchor可以确定控件的相对位置不发生变化
- Windows下搭建MySql Master-Master Replication
1.首先下载最新版的MySql Server (http://dev.mysql.com/downloads/windows/installer/) 2.安装MySql Server到两台机器上 My ...
- MinGW GCC下sleep()函数问题
在MinGW GCC下编译带sleep()函数的测试程序,不管是包含了unistd.h头文件,还是stdio.h.stdlib.h头文件,就是找不到该函数的定义!在linux下,sleep()函数的头 ...
- 1934. Black Spot(spfa)
1934 水题 RE了N久 后来发现是无向图 #include <iostream> #include<cstring> #include<algorithm> # ...
- bzoj3926
题目的意思是叶子不超过20个……听说当初zjoi不少人被坑 分别对每个叶子以它为根dfs出20个dfs树,这样整个树的任何一个子串,都是某个dfs树上一个点到它的一个子孙的路径 每个dfs树,根到叶子 ...
- ElasticSearch Remote Code Execution (CVE-2014-3120)
Elasticsearch is a powerful open source search and analytics engine. The vulnerability allows attack ...