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 ...
随机推荐
- Bug测试报告--俄罗斯方块--新蜂
项目名:俄罗斯方块 组名:新蜂 测试者:韩媛媛(nice!团队) 用户需求规格说明书URL:http://www.cnblogs.com/Boxer1994/p/6084035.html 组长博客UR ...
- cvWaitKey();
1.函数形式:int cvWaitKey(int delay=0 ): 函数功能:cvWaitKey()函数的功能是不断刷新图像,频率时间为delay,单位为ms. 参数: delay——— ...
- SQL Server 索引视图 聚簇索引
创建示例: 朋友的网站速度慢,让我帮忙看下,他用的SQL Server里面 有一个文章表里面有30多万条记录 还有一个用户表里面也差不多17万记录 偏偏当初设计的时候没有冗余字段 很多帖子信息需要JO ...
- HorizontalScrollView水平滑动
xml布局 <HorizontalScrollView android:id="@+id/hsv" android:layout_ ...
- Hadoop入门实践之从WordCount程序说起
这段时间需要学习Hadoop了,以前一直听说Hadoop,但是从来没有研究过,这几天粗略看完了<Hadoop实战>这本书,对Hadoop编程有了大致的了解.接下来就是多看多写了.以Hado ...
- 安装qt5.3.2后,qtcreator在ubuntu 11.04无法启动的问题
在官方网站下载.run文件安装后,qtcreator启动失败,然后找到命令行启动,失败原因如下: shr@shr-Sieyuan:~/Qt5.3.2/Tools/QtCreator/bin$ ./qt ...
- 爱普生 RS330 打印机墨水连供装置墨盒吸墨复位方法
芯片复位方法: 先按充墨键(墨水灯按键),一下一下按,把墨车按停到右侧换墨盒的位置为止(就是右侧框框正中位置), 全程带电操作,停到换墨盒的位置后再按住芯片复位键(墨盒芯片上面白色的小按键)5秒以上再 ...
- linux性能分析工具
概览 uptime dmesg | tail vmstat 1 mpstat -P ALL 1 pidstat 1 iostat -xz 1 free -m sar -n DEV 1 sar -n T ...
- 161014、Comet4J介绍及使用(即时推送)
简介 Comet4J是一个微型的即时推送框架(类似于goeasy),它分为服务端与客户端两部分,你只要将服务器端(JAR文件,目前仅支持Tomcat6.7)放入WEB-INF\lib,客户端(Java ...
- 用grunt搭建自动化的web前端开发环境实战教程(详细步骤)
用grunt搭建自动化的web前端开发环境实战教程(详细步骤) jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用!前端自动化, ...