题目链接: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. 夺命雷公狗—angularjs—6—单条数据的遍历

    我们在实际的工作中常常会处理到一些数据的遍历,这些数据都是后端传到前端的,有些公司会让前端帮忙处理一点遍历的工作,废话不多说,直接上代: <!doctype html> <html ...

  2. 夺命雷公狗---DEDECMS----20dedecms取出栏目页对应的内容

    取出栏目页对应的内容 现在我们的栏目页面是可以完全正常跳转了,那么我们现在需要完成的就是让他的内容全部(电影,连续剧,综艺)分类的显示出来. 我们还是要使用{dede:arclist}标签来取出我们所 ...

  3. Visual Studio 2012 怪异的自动重启

    学生在做项目的过程中遇到这种问题: -------------- 用 Visual Studio 2012  开发W中eb 项目时,最近总是莫名其妙的自动重启. 后来试了一下,发现是只要在页面中输入 ...

  4. 解决PHP在IE浏览器下载文件,中文文件名乱码问题

    前提:我们网站所有文件全部使用的是UTF-8 NO BOM的编码方式 1.找测试重现.360浏览器下载的呵呵,果然文件名是乱码.再请测试在ie浏览器下测试.IE9,8,7也全部是乱码.查看编码就是UT ...

  5. 爱普生 RS330 打印机墨水连供装置墨盒吸墨复位方法

    芯片复位方法: 先按充墨键(墨水灯按键),一下一下按,把墨车按停到右侧换墨盒的位置为止(就是右侧框框正中位置), 全程带电操作,停到换墨盒的位置后再按住芯片复位键(墨盒芯片上面白色的小按键)5秒以上再 ...

  6. 161107、spring异步调用,完美解决!

    项目中,用户抢单,下单需要向对方推送消息,但是加上推送就会造成抢单和下单性能降低,反应变慢,因为抢单下单动作跟推送部分是同步的,现在想改成异步推送. 在Java应用中,绝大多数情况下都是通过同步的方式 ...

  7. js捕捉IE窗口失去焦点事件,判断离开页面刷新或关闭的方法

    js捕捉IE窗口失去焦点事件,判断离开页面刷新或关闭的方法 javascript如何捕捉IE窗口失去焦点事件window.onblur = function(e) { //you code}; 弹框的 ...

  8. NSDictionary to jsonString || 对象转json格式

    -(NSString*)DataTOjsonString:(id)object { NSString *jsonString = nil; NSError *error; NSData *jsonDa ...

  9. Codeforces 733C:Epidemic in Monstropolis(暴力贪心)

    http://codeforces.com/problemset/problem/733/C 题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后, ...

  10. get/post方式调用http接口

    http://www.cnblogs.com/java-pan/tag/HTTP/ http://www.cnblogs.com/snoopylovefiona/p/4730242.html(可做参考 ...