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 ...
随机推荐
- Oracle重置序列(不删除重建方式)
Oracle中一般将自增sequence重置为初始1时,都是删除再重建,这种方式有很多弊端,依赖它的函数和存储过程将失效,需要重新编译. 不过还有种巧妙的方式,不用删除,利用步长参数,先查出seque ...
- 编译php时的一个脚本
./configure --prefix=/usr/local/php \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext ...
- URL 中#号,? ,&的作用 (摘抄整理 链接为学习地址)
1. 一峰的网络日志:http://www.ruanyifeng.com/blog/2011/03/url_hash.html get: 1.页面滚动到指定页面的指定位置 (eg: http://ww ...
- DELPHI出现无法加载dclite50.bpl的解决办法(转)
现象: Borland Integrated Translation Environment 加载出错 解决办法: 我的电脑--->(鼠标右键)属性--->高级--->(性能)设置- ...
- linux设备驱动归纳总结(七):1.时间管理与内核延时【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-100005.html linux设备驱动归纳总结(七):1.时间管理与内核延时 xxxxxxxxxxx ...
- 161208、Java enum 枚举还可以这么用
在大部分编程语言中,枚举类型都会是一种常用而又必不可少的数据类型,Java中当然也不会例外.然而,Java中的Enum枚举类型却有着许多你意想不到的用法,下面让我们一起来看看. 先来看一段代码示例: ...
- rtsp里面的音频类型,大部分都默认规定了样本大小的。
从src/audio_output/common.c里面的函数aout_BitsPerSample可知,rtsp里面的音频类型,大部分都默认规定了样本bit大小的.即是,一个音频编码类型,对应一个固定 ...
- mysql语句
查询字段长度:SELECT MAX(LENGTH(pd)) FROM `table` where id=2;来检查当前表中字段的字符集设置.show full fields from tableNam ...
- HDU 5724:Chess(博弈 + 状压)
http://acm.hdu.edu.cn/showproblem.php?pid=5724 Chess Problem Description Alice and Bob are playing ...
- C#:数据交互
JS与Web交互:http://www.docin.com/p-76710976.html 一.WinForm的WebBrowser控件与JS交互数据: 1.C#类内的代码执行JS脚本函数: 给C#类 ...