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

Description

Calculate the number of toys that land in each bin of a partitioned toy box. 
Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for John to find his favorite toys.

John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. 
 
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.

Input

The input file contains one or more problems. The first line of a problem consists of six integers, n m x1 y1 x2 y2. The number of cardboard partitions is n (0 < n <= 5000) and the number of toys is m (0 < m <= 5000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1,y1) and (x2,y2), respectively. The following n lines contain two integers per line, Ui Li, indicating that the ends of the i-th cardboard partition is at the coordinates (Ui,y1) and (Li,y2). You may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. The next m lines contain two integers per line, Xj Yj specifying where the j-th toy has landed in the box. The order of the toy locations is random. You may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. The input is terminated by a line consisting of a single 0.

Output

The output for each problem will be one line for each separate bin in the toy box. For each bin, print its bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. Bins are numbered from 0 (the leftmost bin) to n (the rightmost bin). Separate the output of different problems by a single blank line.

Sample Input

  1. 5 6 0 10 60 0
  2. 3 1
  3. 4 3
  4. 6 8
  5. 10 10
  6. 15 30
  7. 1 5
  8. 2 1
  9. 2 8
  10. 5 5
  11. 40 10
  12. 7 9
  13. 4 10 0 10 100 0
  14. 20 20
  15. 40 40
  16. 60 60
  17. 80 80
  18. 5 10
  19. 15 10
  20. 25 10
  21. 35 10
  22. 45 10
  23. 55 10
  24. 65 10
  25. 75 10
  26. 85 10
  27. 95 10
  28. 0

Sample Output

  1. 0: 2
  2. 1: 1
  3. 2: 1
  4. 3: 1
  5. 4: 0
  6. 5: 1
  7.  
  8. 0: 2
  9. 1: 2
  10. 2: 2
  11. 3: 2
  12. 4: 2

Hint

As the example illustrates, toys that fall on the boundary of the box are "in" the box.
 
 
  1. /*
  2. poj 2318 叉积+二分
  3.  
  4. 一个矩形,有被若干直线分成N个格子,给出一个点的坐标,问你该点位于哪个点中。
  5. 知识点:其实就是点在凸四边形内的判断,若利用叉积的性质,可以二分求解。
  6.  
  7. 叉积的结果也是一个向量,是垂直于向量a,b所形成的平面,如果看成三维坐标的话是在 z 轴上,上面结果是它的模。
  8. 方向判定:右手定则,(右手半握,大拇指垂直向上,四指右向量a握向b,大拇指的方向就是叉积的方向)
  9. 叉积的意义:
  10. 1:其结果是a和b为相邻边形成平行四边形的面积。
  11. 2:结果有正有负,有sin(a,b)可知和其夹角有关,夹角大于180°为负值。
    本题可以通过叉积的正负来判断它在直线的哪边
  12.  
  13. hhh-2016-05-04 19:49:26
  14. */
  15. #include <iostream>
  16. #include <vector>
  17. #include <cstring>
  18. #include <string>
  19. #include <cstdio>
  20. #include <queue>
  21. #include <algorithm>
  22. #include <functional>
  23. #include <map>
  24. using namespace std;
  25. #define lson (i<<1)
  26. #define rson ((i<<1)|1)
  27. typedef long long ll;
  28. const int maxn = 40010;
  29. int tot;
  30. int mod;
  31. int n,m;
  32. int x1,x2,y1,y2;
  33.  
  34. struct Point
  35. {
  36. int x,y;
  37. Point() {}
  38. Point(int _x,int _y)
  39. {
  40. x = _x,y = _y;
  41. }
  42. Point operator -(const Point &b)const
  43. {
  44. return Point(x-b.x,y-b.y);
  45. }
  46. int operator ^(const Point &b)const
  47. {
  48. return x*b.y-y*b.x;
  49. }
  50. };
  51.  
  52. struct Line
  53. {
  54. Point s,t;
  55. Line() {}
  56. Line(Point _s,Point _t)
  57. {
  58. s = _s;
  59. t = _t;
  60. }
  61. };
  62. int tans[maxn];
  63. Line line[maxn];
  64. Point p;
  65. int cal(int mid)
  66. {
  67. return (line[mid].t-p)^(line[mid].s-p);
  68. }
  69.  
  70. int main()
  71. {
  72. int flag = 1;
  73. while(scanf("%d",&n) && n)
  74. {
  75. if(!flag)
  76. printf("\n");
  77. scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
  78. flag = 0;
  79. line[n] = Line(Point(x2,y1),Point(x2,y2));
  80. memset(tans,0,sizeof(tans));
  81. for(int i = 0; i < n; i++)
  82. {
  83. scanf("%d%d",&x1,&x2);
  84. line[i] = Line(Point(x1,y1),Point(x2,y2));
  85. }
  86. while(m--)
  87. {
  88. scanf("%d%d",&x1,&y1);
  89. int l = 0, r = n;
  90. int mid,ans;
  91. p = Point(x1,y1);
  92. while(l <= r)
  93. {
  94. mid = (l+r)>>1;
  95. if(cal(mid) > 0)
  96. {
  97. ans = mid;
  98. r = mid-1;
  99. }
  100. else
  101. {
  102. l = mid+1;
  103. }
  104. }
  105. tans[ans]++;
  106. }
  107. for(int i = 0; i <= n; i++)
  108. {
  109. printf("%d: %d\n",i,tans[i]);
  110. }
  111. }
  112. return 0;
  113. }

  

poj 2318 叉积+二分的更多相关文章

  1. POJ 2318 叉积判断点与直线位置

    TOYS   Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom ...

  2. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  3. POJ 2318 (叉积) TOYS

    题意: 有一个长方形,里面从左到右有n条线段,将矩形分成n+1个格子,编号从左到右为0~n. 端点分别在矩形的上下两条边上,这n条线段互不相交. 现在已知m个点,统计每个格子中点的个数. 分析: 用叉 ...

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

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

  5. POJ 2318 TOYS | 二分+判断点在多边形内

    题意: 给一个矩形的区域(左上角为(x1,y1) 右下角为(x2,y2)),给出n对(u,v)表示(u,y1) 和 (v,y2)构成线段将矩形切割 这样构成了n+1个多边形,再给出m个点,问每个多边形 ...

  6. POJ 2318/2398 叉积性质

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

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

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

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

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

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

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

随机推荐

  1. C程序设计-----第1次作业

    一. PTA作业.    在完成PTA作业的时候我没有认真读题.每次都是提交完整代码 6-1(1) #include <stdio.h> //P++等价于(p)++还是等价于*(p++)? ...

  2. Oracle查询用户权限

    Oracle查询用户权限 -- 确定角色的权限select * from role_tab_privs ;              包含了授予角色的对象权限select * from role_ro ...

  3. python实现简单tftp(基于udp)

    tftp是基于udp的协议 实现简单的tftp,首先要有tftp的协议图. tftp默认接收端口为69,但每次有连接过来后,tftp会随机分配一个端口来专门为这个连接来服务. 操作码:1.上传 2.下 ...

  4. aws中的路由表

    参考官方文档: 由表中包含一系列被称为路由的规则,可用于判断网络流量的导向目的地. 在您的 VPC 中的每个子网必须与一个路由表关联:路由表控制子网的路由.一个子网一次只能与一个路由表关联,但您可以将 ...

  5. JMeter入门(03)多台JMeter联合测试

    一.配置各个节点 1.配置jmeter.properties # Remote Hosts - comma delimited#remote_hosts=localhost:1099,localhos ...

  6. JWT(JSON Web Token) 多网站的单点登录,放弃session

    多个网站之间的登录信息共享, 一种解决方案是基于cookie - session的登录认证方式,这种方式跨域比较复杂. 另一种替代方案是采用基于算法的认证方式, JWT(json web token) ...

  7. Python 自动化 第一周

    1.Python简介 1.1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时 ...

  8. SQL知识点

    关系型数据库:MySql非关系型数据库:Redis(以键值对的方式) SQL分几类: DDL:数据定义语言:create.alter.drop.truncate DML:数据操作语言:insert.d ...

  9. 在服务器上,配置redis可以外网访问

    首先linux开放默认端口6379打开redis配置文件redis-conf注释掉 bind 127.0.0.1(默认只有本地主要才能访问)这个注释掉现在处于受保护的状态,外网连不上,因为没有密码 在 ...

  10. Testlink1.7.5安装部署

    Testlink1.7.5安装部署 1   下载安装wamp5:下载地址:http://www.duote.com/soft/56016.html wamp5是apache.mysql.PHP的集成环 ...