题目链接: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的更多相关文章

  1. acdream1197 Points In Cuboid(hash树状数组)

    题目链接:http://acdream.info/problem?pid=1197 题意:给出三维空间n个点,m个查询,每次查询某个立方体内的点的个数. 思路:按照一维排序,根据查询插入,其他两位用二 ...

  2. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  3. [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. ...

  4. 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 ...

  5. K closest points

    Find the K closest points to a target point in a 2D plane. class Point { public int x; public int y; ...

  6. 【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 ...

  7. 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. ...

  8. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  9. [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 ...

随机推荐

  1. haskell笔记1

    haskell platform下载:https://www.haskell.org/platform/ 进入haskell控制台,终端输入 $ ghci 编译文件 :l file.hs 数组操作 & ...

  2. Oracle数据类型总结

    一 字符串类型 1.1:CHAR类型 CHAR(size [BYTE | CHAR]) CHAR类型,定长字符串,会用空格填充来达到其最大长度.非NULL的CHAR(12)总是包含12字节信息.CHA ...

  3. 夺命雷公狗ThinkPHP项目之----企业网站18之网站配置列表页的完成

    我们点击下配置列表即可查看我们列表页的配置信息了: 其实这个最简单了,首先我们先来完成他控制器的代码: public function lists(){ $mod = M('Conf')->se ...

  4. 《Focus On 3D Terrain Programming》中一段代码的注释二

    取自<Focus On 3D Terrain Programming>中的一段: bool CTERRAIN::MakeTerrainFault( int iSize, int iIter ...

  5. iOS,破冰!

    首发:个人博客,更新&纠错&回复 iOS,破冰! 今年学的技术,以iOS自学为成本最高昂:花几千块买了台mac mini电脑,又前后买了6本书籍,从头到尾是30天时间,当然,这30天里 ...

  6. Mongodb 笔记08 了解应用的动态、数据管理、持久性

    了解应用的动态 1. 了解正在进行的操作:db.currentOp() , 可以加过滤条件,从而只显示符合条件的结果. 1). 寻找有问题的操作:db.currentOp() 最常见的操作就是用来寻找 ...

  7. 鸟哥的Linux私房菜之学习shell script

    运行程序的时候一般都是创建一个子程序来执行,所以子程序中的变量什么的在当前的shell下没法使用,但是如果使用source来执行就可以在当前shell下执行程序 shift 1 去掉第一个参数,后面接 ...

  8. 第一轮复习Servlet day04

    * 数据的传送接收:后台通过request发送:req.setAttribute("emps", list); req.getRequestDispatcher("emp ...

  9. TI BLE CC2541的SPI主模式

    SPI就是用4条线来串行传输数据, 2541只能用模拟的方式用GPIO来做. //*********************************************************** ...

  10. tr DEMO

    测试数据: [weblogic@etp-mall-dev7][/tmp]$ cat msn.txt aaa bbb bbb ccc ccc ddd bbb eee aaa ccc bbb sss 转换 ...