题目链接:http://acdream.info/problem?pid=1197

题意:给出一些点。每次给出一个长方体,问在长方体中的点的个数。

思路:kd-tree。

  1. const int N=111111;
  2.  
  3. struct node
  4. {
  5. int x[3];
  6. int L,R;
  7. };
  8.  
  9. node a[N];
  10. int root,n,m;
  11.  
  12. void insert(int u,int k,int d)
  13. {
  14. d%=3;
  15. if(a[k].x[d]<a[u].x[d])
  16. {
  17. if(a[u].L==-1) a[u].L=k;
  18. else insert(a[u].L,k,d+1);
  19. }
  20. else
  21. {
  22. if(a[u].R==-1) a[u].R=k;
  23. else insert(a[u].R,k,d+1);
  24. }
  25. }
  26.  
  27. int p[3],q[3],ans;
  28.  
  29. void cal(int u,int d)
  30. {
  31. if(u==-1) return;
  32. int i;
  33. for(i=0;i<3;i++) if(a[u].x[i]<p[i]||a[u].x[i]>q[i]) break;
  34. if(i==3) ans++;
  35. d%=3;
  36. if(a[u].x[d]>=p[d]) cal(a[u].L,d+1);
  37. if(a[u].x[d]<=q[d]) cal(a[u].R,d+1);
  38. }
  39.  
  40. void deal()
  41. {
  42. int i;
  43. for(i=1;i<=n;i++)
  44. {
  45. a[i].L=a[i].R=-1;
  46. scanf("%d%d%d",&a[i].x[0],&a[i].x[1],&a[i].x[2]);
  47. if(i==1) root=i;
  48. else insert(root,i,0);
  49. }
  50.  
  51. m=getInt();
  52. while(m--)
  53. {
  54. for(i=0;i<3;i++) scanf("%d",&p[i]);
  55. for(i=0;i<3;i++)
  56. {
  57. scanf("%d",&q[i]);
  58. if(p[i]>q[i]) swap(p[i],q[i]);
  59. }
  60. ans=0;
  61. cal(root,0);
  62. printf("%d\n",ans);
  63. }
  64. }
  65.  
  66. int main()
  67. {
  68.  
  69. int num=0;
  70. while(scanf("%d",&n)!=-1)
  71. {
  72. printf("Case #%d:\n",++num);
  73. deal();
  74. }
  75. }

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. NOIP201205Vigenère密码

                                   NOIP201205Vigenère密码 [问题描述]   16 世纪法国外交家Blaise de Vigenère设计了一种多表密码加密 ...

  2. SessionHelper

    MXS&Vincene  ─╄OvЁ  &0000009 ─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...

  3. 图像处理控件ImageGear for .NET教程如何为应用程序 添加DICOM功能(2)

    在前面的一些关于图像处理控件ImageGear for .NET文章<图像处理控件ImageGear for .NET教程: 添加DICOM功能(1)>中讲解了如何对应用程序添加DICOM ...

  4. sql多表查询(out join,inner join, left join, right join)

    left join以左表为基准显示所有左表的信息,在on中有符合条件的其他表也显示出来 right join则相反 inner join的只显示on中符合条件的 1 使用多个表格 在「world」资料 ...

  5. 161117、使用spring声明式事务抛出 identifier of an instance of

    今天项目组有成员使用spring声明式事务出现下面异常,这里跟大家分享学习下. 异常信息: org.springframework.orm.hibernate3.HibernateSystemExce ...

  6. laravel队列

    三种情况: queue:work 默认只执行一次队列请求, 当请求执行完成后就终止; queue:listen 监听队列请求, 只要运行着, 就能一直接受请求, 除非手动终止; queue:work ...

  7. 【翻译】了解ASP.NET MVC的HTML助手

    原文:Understanding HTML Helpers in ASP.NET MVC 作 者:Shailendra Chauhan works as Software Analyst at rep ...

  8. 那些情况该使用它们spin_lock到spin_lock_irqsave【转】

    转自:http://blog.csdn.net/wesleyluo/article/details/8807919 权声明:本文为博主原创文章,未经博主允许不得转载. Spinlock的目的是用来同步 ...

  9. 【原创】Nexus搭建Maven私服

    前言: 公司一般都有个自己的私服来管理各种jar包,原因大概有这么3个,分别是: 1.有的公司不能访问外网,只能通过私服来管理jar包和插件: 2.公司网速比较慢,通过公司的私服来获取jar包比较快: ...

  10. 20145227《Java程序设计》第10周学习总结

    20145227<Java程序设计>第10周学习总结 教材学习内容总结 网络编程 就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收 ...