题目链接: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. microsoft .netframework Available Source Code Components

    http://referencesource.microsoft.com/netframework.aspx http://blogs.msdn.com/b/dotnet/archive/2012/0 ...

  2. android简单的夜间模式

    现在android项目values下打 attrs.xml <?xml version="1.0" encoding="utf-8"?> <r ...

  3. 【翻译】了解ASP.NET MVC的HTML助手

    原文:Understanding HTML Helpers in ASP.NET MVC 作 者:Shailendra Chauhan works as Software Analyst at rep ...

  4. dir cmd、the DIR Command、windows

    原因   :如何在windows下的cmd.exe中只列出文件名? solve : dir \a:-d \b Extend Reading : dir [drive:][path][filename] ...

  5. FastDFS配置说明

    前面了解了fastdfs的原理,接下来就熟悉一下安装过程,准备了三台机器,一台模拟client,一台模拟storage,一台模拟tracker.     三台机器均为debian6,系统为最小化安装, ...

  6. NEON简介【转】

    转自:http://blog.csdn.net/fengbingchun/article/details/38020265 版权声明:本文为博主原创文章,未经博主允许不得转载. “ARM Advanc ...

  7. weblogic从应用服务器找不到主应用服务器

    报错信息: weblogic.cluster.replication.ApplicationUnavailableException: WebApp with contextPath: not fou ...

  8. Cacti Install

    一.Cacti简介 Cacti是通过snmpget来获取数据,使用RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数.它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查 ...

  9. java 字符串处理

    第一张: 第二张:

  10. 如何在ecshop商品详情页显示供货商信息

    以下范例以ecshop2.7.2原型做为修改: 1.首先需要修改程序文件,将供货商读取出来,然后赋值给模板,   打开文件 /goos.php,   在                   $smar ...