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 ...
随机推荐
- 夺命雷公狗---DEDECMS----23dedecms修改内容页面展示的信息
我们在网站上不管点击那个影视作品的A连接都是进入到一个同样的页面,因为他们是一个模版文件: 我们还没有对这个模版进行任何的修改,所以我们要在内容模版增加标签取出对应的影视作品,而且导航条也是按照模版上 ...
- [sinatra] Just Do It: Learn Sinatra, Part One Darren Jones
1. Install sinatra gem gem install sinatra --no-ri --no-rdoc 2. Basic App #!/usr/bin/ruby require 's ...
- 【crunch bang】论坛tint2配置讨论贴
地址: http://crunchbang.org/forums/viewtopic.php?id=3232
- 有关OpenGL着色语言(一)
刚接触OpenGL着色语言...,不定期增加内容 1.OpenGL着色语言(GLSL)是什么? 用于OpenGL的面向过程的高级着色语言,是近年来图形编程领域中出现的最重要的新型开发技术,使用Open ...
- Eclipse帮助文档配置
Force Eclipse To Use Local Javadocs For Context-Sensitive Help 转自:http://www.gnostice.com/nl_article ...
- 161115、MyBatis 通过包含的jdbcType类型
MyBatis常用jdbcType类型 BIT FLOAT CHAR TIMESTAMP OTHER UNDEFINEDTINYI ...
- Thinkphp用exp表达式执行mysql语句,查询某字段不为空is not null,自动增值
Thinkphp用exp表达式执行mysql语句,查询某字段不为空is not null,自动增值 Thinkphp 的文档经常不够完整的表达MYSQL的各种组合,is not null在thinkp ...
- 安装centos7.1 32bit时,没有可用的网络设备的解决方法
安装的系统镜像文件:CentOS-7-i386-LiveGNOME-1511.iso 虚拟机版本: 问题: 原因: 原先我在这里选择的时候,以为自己安装的不是64位的,所以没有选择centos 64, ...
- PHP String 函数
[http://www.w3school.com.cn/php/php_ref_string.asp ] PHP String 简介 String 字符串函数允许您对字符串进行操作. 安装 Strin ...
- 多线程并发流程控制之dispatch_group 有关函数
A B C D 4个并发下载任务,怎样在第一时间知道任务全部完成? dispatch_group 可以帮我们实现这样的控制. 上代码,看说明. dispatch_group_t group = dis ...