1. // 题意:问你每个区域有多少个点
  2. // 思路:数据小可以直接暴力
  3. // 也可以二分区间
  4.  
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <map>
  10. #include <set>
  11. #include <queue>
  12. #include <stdlib.h>
  13. #include <cmath>
  14. using namespace std;
  15. typedef long long LL;
  16. const LL inf = 1e18;
  17. const int N = ;
  18.  
  19. struct Point{
  20. int x,y;
  21. Point(){}
  22. Point(int _x,int _y){
  23. x=_x;y=_y;
  24. }
  25. Point operator -(const Point &b)const{
  26. return Point(x-b.x,y-b.y);
  27. }
  28. int operator *(const Point &b)const{
  29. return x*b.x+y*b.y;
  30. }
  31. int operator ^(const Point &b)const{
  32. return x*b.y-y*b.x;
  33. }
  34. };
  35.  
  36. struct Line{
  37. Point s,e;
  38. Line(){}
  39. Line(Point _s,Point _e){
  40. s=_s,e=_e;
  41. }
  42. };
  43.  
  44. int xmult(Point p0,Point p1,Point p2){
  45. return (p1-p0)^(p2-p0);
  46. }
  47.  
  48. Line line[N];
  49. int ans[N];
  50. int main(){
  51. int n,m,x1,y1,x2,y2;
  52. bool first = true;
  53. while(~scanf("%d",&n)&&n){
  54. if(first) first=false;
  55. else printf("\n");
  56. scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
  57. for(int i=;i<n;i++){
  58. int x,y;
  59. scanf("%d%d",&x,&y);
  60. line[i]=Line(Point(x,y1),Point(y,y2));
  61. }
  62. line[n]=Line(Point(x2,y1),Point(x2,y2));
  63. int x,y;
  64. Point p;
  65. memset(ans,,sizeof(ans));
  66. int tem;
  67. while(m--){
  68. scanf("%d%d",&x,&y);
  69. p = Point(x,y);
  70. int l=,r=n,mid;
  71. while(l<=r){
  72. mid=(l+r)>>;
  73. if(xmult(p,line[mid].s,line[mid].e)<){
  74. tem=mid;
  75. r=mid-;
  76. }
  77. else l=mid+;
  78. }
  79. ans[tem]++;
  80. }
  81. for(int i=;i<=n;i++) printf("%d: %d\n",i,ans[i]);
  82. }
  83. return ;
  84. }
  1. // POJ 2398和2318差不多 多了排序和统计输出
  2.  
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <map>
  8. #include <set>
  9. #include <queue>
  10. #include <stdlib.h>
  11. #include <cmath>
  12. using namespace std;
  13. typedef long long LL;
  14. const LL inf = 1e18;
  15. const int N = ;
  16.  
  17. struct Point{
  18. int x,y;
  19. Point(){}
  20. Point(int _x,int _y){
  21. x=_x;y=_y;
  22. }
  23. Point operator -(const Point &b)const{
  24. return Point(x-b.x,y-b.y);
  25. }
  26. int operator *(const Point &b)const{
  27. return x*b.x+y*b.y;
  28. }
  29. int operator ^(const Point &b)const{
  30. return x*b.y-y*b.x;
  31. }
  32. };
  33.  
  34. struct Line{
  35. Point s,e;
  36. Line(){}
  37. Line(Point _s,Point _e){
  38. s=_s,e=_e;
  39. }
  40. };
  41.  
  42. int xmult(Point p0,Point p1,Point p2){
  43. return (p1-p0)^(p2-p0);
  44. }
  45.  
  46. bool cmp(Line a,Line b){
  47. return a.s.x<b.s.x;
  48. }
  49.  
  50. Line line[N];
  51. int ans[N];
  52. int num[N];
  53. int main(){
  54. int n,m,x1,y1,x2,y2;
  55. while(~scanf("%d",&n)&&n){
  56. memset(num,,sizeof(num));
  57. scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
  58. for(int i=;i<n;i++){
  59. int x,y;
  60. scanf("%d%d",&x,&y);
  61. line[i]=Line(Point(x,y1),Point(y,y2));
  62. }
  63. line[n]=Line(Point(x2,y1),Point(x2,y2));
  64. sort(line,line+n+,cmp);
  65. int x,y;
  66. Point p;
  67. memset(ans,,sizeof(ans));
  68. int tem;
  69. while(m--){
  70. scanf("%d%d",&x,&y);
  71. p = Point(x,y);
  72. int l=,r=n,mid;
  73. while(l<=r){
  74. mid=(l+r)>>;
  75. if(xmult(p,line[mid].s,line[mid].e)<){
  76. tem=mid;
  77. r=mid-;
  78. }
  79. else l=mid+;
  80. }
  81. ans[tem]++;
  82. }
  83. for(int i=;i<=n;i++){
  84. num[ans[i]]++;
  85. }
  86. printf("Box\n");
  87. for(int i=;i<=n;i++) {
  88. if(num[i]>)
  89. printf("%d: %d\n",i,num[i]);
  90. }
  91. }
  92. return ;
  93. }

二分+叉积判断方向 poj 2318 2398的更多相关文章

  1. POJ 2318/2398 叉积性质

    2318 2398 题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里. 思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧 ...

  2. POJ 2318--TOYS(二分找点,叉积判断方向)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17974   Accepted: 8539 Description ...

  3. TOYS - POJ 2318(计算几何,叉积判断)

    题目大意:给你一个矩形的左上角和右下角的坐标,然后这个矩形有 N 个隔板分割成 N+1 个区域,下面有 M 组坐标,求出来每个区域包含的坐标数.   分析:做的第一道计算几何题目....使用叉积判断方 ...

  4. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  5. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

  6. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  7. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  8. poj 2318(叉积判断点在线段的哪一侧)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13120   Accepted: 6334 Description ...

  9. POJ 2318 TOYS【叉积+二分】

    今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...

随机推荐

  1. windows下顽固软件卸载不了的解决方法

    下面以autocad2012举例: cad2012卸载显示 “无法获得同类产品” 而且也安装不上. 解决方法:1,开始>运行>输入"regedit",找到下面的注册表路 ...

  2. C#调用Win32 api学习总结

    从.NET平台调用Win32 API Win32 API可以直接控制Microsoft Windows的核心,因为API(Application Programming Interface)本来就是微 ...

  3. brew命令

    下面参考下网友的总结: 查看brew的帮助 brew –help 安装软件 brew install git 卸载软件 brew uninstall git 搜索软件 brew search git ...

  4. Android The content of the adapter has changed but ListView did not receive a notification

    The content of the adapter has changed but ListView did not receive a notification. Make sure the co ...

  5. mysqldump常用于MySQL数据库逻辑备份

    mysqldump常用于MySQL数据库逻辑备份. 1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump ...

  6. 结巴分词标注兼容_ICTCLAS2008汉语词性标注集

    计算所汉语词性标记集Version 3.0制订人:刘群 张华平 张浩计算所汉语词性标记集... 10. 说明... 11. 名词 (1个一类,7个二类,5个三类) 22. 时间词(1个一类,1个二类) ...

  7. 自定义View(6)paint设置图图层重叠时的显示方式,包含清空canvas

    Paint.setXfermode 这个函数设置两个图层相交时的模式 在已有的图层上绘图将会在其上面添加一层新的图层. 如果新的图层是完全不透明的,那么它将完全遮挡住下面的图层,而setXfermod ...

  8. git push提示或错误

    当 git 和 gerrit 一起使用的时候,你创建了一个 tag,现在需要 push 到远程仓库,当你没有权限的时候,会出现如下提示: $ git push origin v20150203 Tot ...

  9. 函数buf_page_init_for_read

    /********************************************************************//** Function which inits a pag ...

  10. 工作中的 Vim 和 git

    ————————Vim———————— 1. gf 可以转到文件中指明路径的文件. 这样可以实现文件的快速切换. ctrl+o: A -> B,  返回A ctrl+6: A.B之间快速切换 2 ...