题目链接: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. oracle的例程

    oracle只有在具备sysoper和sysdba权限下才能启动和关闭例程 关闭例程: --正常关闭(等待当前连接的所有用户与数据库断开) shutdown normal; --立即关闭(回退活动的事 ...

  2. ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境(转)

    原文地址:http://blog.csdn.net/shangyuan21/article/details/18153605 我们都知道开发iPhone等ios平台的移动应用时需要使用Mac本,但是M ...

  3. windows下pip升级到8.1.2

    升级pip只要切换到easy_install-3.5目录下:  easy_install-3.5 pip==8.1.2

  4. windows下快速启动 nginx 和 php-cgi 的两个批处理

    这是启动的批处理: set nginx=D:\nginx-1.9.5\ set php=D:\php\ start /MIN %nginx%nginx.exe start /MIN %php%php- ...

  5. 一个Convert、TryParse数据转换的问题

    今天在进行数据转换的时候遇到一个问题,记录下,希望看到的童鞋有点用哦~ Convert.ToInt32(0.80155023553515) 结果为1 但是以下的做法,就不是想当然的结果咯~ int.T ...

  6. ActiveMQ消息的可靠性机制(转)

    文章转自:http://www.linuxidc.com/Linux/2013-02/79664.htm 1.JMS消息确认机制 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通 ...

  7. 【python cookbook】【数据结构与算法】2 从任意长度的可迭代对象中分解元素

    从某个可迭代对象中分解出N个元素,但是可迭代对象的长度可能超过N,会出现“分解值过多”的异常: 使用“*表达式”来解决该问题: Python 3.4.3 (v3.4.3:9b73f1c3e601, F ...

  8. iOS delegate, 代理/委托与协议.

    之前知知道iOS协议怎么写, 以为真的跟特么java接口一样, 后来发现完全不是. 首先, 说说应用场景, 就是当你要用一个程序类, 或者说逻辑类, 去控制一个storyboard里面的label, ...

  9. PHP数组的一些常用函数

    [数组排序]sort()低到高,rsort()高到低.保持键值对应关系使用 asort()和arsort().对键排序ksort()和krsort().随机排序 shuffle(). [数组key相关 ...

  10. 8、web入门回顾/ Http

    1 web入门回顾 web入门 1)web服务软件作用: 把本地资源共享给外部访问 2)tomcat服务器基本操作      : 启动:  %tomcat%/bin/startup.bat 关闭: % ...