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 ...
随机推荐
- NOIP201205Vigenère密码
NOIP201205Vigenère密码 [问题描述] 16 世纪法国外交家Blaise de Vigenère设计了一种多表密码加密 ...
- SessionHelper
MXS&Vincene ─╄OvЁ &0000009 ─╄OvЁ MXS&Vincene MXS&Vincene ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...
- 图像处理控件ImageGear for .NET教程如何为应用程序 添加DICOM功能(2)
在前面的一些关于图像处理控件ImageGear for .NET文章<图像处理控件ImageGear for .NET教程: 添加DICOM功能(1)>中讲解了如何对应用程序添加DICOM ...
- sql多表查询(out join,inner join, left join, right join)
left join以左表为基准显示所有左表的信息,在on中有符合条件的其他表也显示出来 right join则相反 inner join的只显示on中符合条件的 1 使用多个表格 在「world」资料 ...
- 161117、使用spring声明式事务抛出 identifier of an instance of
今天项目组有成员使用spring声明式事务出现下面异常,这里跟大家分享学习下. 异常信息: org.springframework.orm.hibernate3.HibernateSystemExce ...
- laravel队列
三种情况: queue:work 默认只执行一次队列请求, 当请求执行完成后就终止; queue:listen 监听队列请求, 只要运行着, 就能一直接受请求, 除非手动终止; queue:work ...
- 【翻译】了解ASP.NET MVC的HTML助手
原文:Understanding HTML Helpers in ASP.NET MVC 作 者:Shailendra Chauhan works as Software Analyst at rep ...
- 那些情况该使用它们spin_lock到spin_lock_irqsave【转】
转自:http://blog.csdn.net/wesleyluo/article/details/8807919 权声明:本文为博主原创文章,未经博主允许不得转载. Spinlock的目的是用来同步 ...
- 【原创】Nexus搭建Maven私服
前言: 公司一般都有个自己的私服来管理各种jar包,原因大概有这么3个,分别是: 1.有的公司不能访问外网,只能通过私服来管理jar包和插件: 2.公司网速比较慢,通过公司的私服来获取jar包比较快: ...
- 20145227《Java程序设计》第10周学习总结
20145227<Java程序设计>第10周学习总结 教材学习内容总结 网络编程 就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收 ...