acdream1197 Points In Cuboid
题目链接:http://acdream.info/problem?pid=1197
题意:给出一些点。每次给出一个长方体,问在长方体中的点的个数。
思路:kd-tree。
const int N=111111;
struct node
{
int x[3];
int L,R;
};
node a[N];
int root,n,m;
void insert(int u,int k,int d)
{
d%=3;
if(a[k].x[d]<a[u].x[d])
{
if(a[u].L==-1) a[u].L=k;
else insert(a[u].L,k,d+1);
}
else
{
if(a[u].R==-1) a[u].R=k;
else insert(a[u].R,k,d+1);
}
}
int p[3],q[3],ans;
void cal(int u,int d)
{
if(u==-1) return;
int i;
for(i=0;i<3;i++) if(a[u].x[i]<p[i]||a[u].x[i]>q[i]) break;
if(i==3) ans++;
d%=3;
if(a[u].x[d]>=p[d]) cal(a[u].L,d+1);
if(a[u].x[d]<=q[d]) cal(a[u].R,d+1);
}
void deal()
{
int i;
for(i=1;i<=n;i++)
{
a[i].L=a[i].R=-1;
scanf("%d%d%d",&a[i].x[0],&a[i].x[1],&a[i].x[2]);
if(i==1) root=i;
else insert(root,i,0);
}
m=getInt();
while(m--)
{
for(i=0;i<3;i++) scanf("%d",&p[i]);
for(i=0;i<3;i++)
{
scanf("%d",&q[i]);
if(p[i]>q[i]) swap(p[i],q[i]);
}
ans=0;
cal(root,0);
printf("%d\n",ans);
}
}
int main()
{
int num=0;
while(scanf("%d",&n)!=-1)
{
printf("Case #%d:\n",++num);
deal();
}
}
acdream1197 Points In Cuboid的更多相关文章
- acdream1197 Points In Cuboid(hash树状数组)
题目链接:http://acdream.info/problem?pid=1197 题意:给出三维空间n个点,m个查询,每次查询某个立方体内的点的个数. 思路:按照一维排序,根据查询插入,其他两位用二 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Max Points on a Line 共线点个数
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- LeetCode:Max Points on a Line
题目链接 Given n points on a 2D plane, find the maximum number of points that lie on the same straight l ...
- K closest points
Find the K closest points to a target point in a 2D plane. class Point { public int x; public int y; ...
- 【leetcode】Max Points on a Line
Max Points on a Line 题目描述: Given n points on a 2D plane, find the maximum number of points that lie ...
- Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- [LeetCode OJ] Max Points on a Line
Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...
- [UCSD白板题] Points and Segments
Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...
随机推荐
- Java高效编程之二【对所有对象都通用的方法】
对于所有对象都通用的方法,即Object类的所有非final方法(equals.hashCode.toString.clone和finalize)都有明确的通用约定,都是为了要被改写(override ...
- android SDK安装容易出错的原因
1.实际上,安卓SDK安装之后,拷贝到其他的机子上面.配置一下环境变量,就可以跑起来的 2.但是拷贝到其他的机子上面临着一个问题就是Eclipse已经配置了的android环境,需要在新的机子上面修改 ...
- 【secureCRT】设置自动连接会话+设置自动连接上次使用的会话:
- Linux系统查看系统是32位还是64位方法总结【转】
转自:http://www.cnblogs.com/kerrycode/p/3785768.html 这篇博客是总结.归纳查看Linux系统是32位还是64位的一些方法,很多内容来自网上网友的博客.本 ...
- weblogic安装失败
weblogic无法安装所选应用程序 Exception in AppMerge flows' progression Exception in AppMerge flows' progression ...
- Oracle 临时表
一.临时表的介绍: Oracle的临时表只存在于某个会话或者事物的生命周期里,此时临时表中的数据只对当前这个会话可见. 临时表经常被用于存放一个操作的中间数据(数据处理的中间环节). 临时表由于不产生 ...
- Mysql query log
一.查询日志的概念: 查询日志记录MySQL中所有的query,通过"--log[=file_name]"来打开该功能.由于记录了所有的query,包括所有的select,体积比较 ...
- NSData NSDate NSString NSArray NSDictionary 相互转换
// NSData NSDate NSString NSArray NSDictionary json NSString *string = @"hello word"; NSDa ...
- HDU 4315:Climbing the Hill(阶梯博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...
- SQLServer学习笔记<>sql的范围内查找,sql数据类型,字符串处理函数
sql的范围内查找 (1)between.....and用法 通常情况下我们查找一个在某固定区域内的所有记录,可以采用>=,<=来写sql语句,例如:查找订单价格在1000到2000之间的 ...