poj 2318 叉积判断点在线的某一侧 + 二分
来源:互联网 发布:第四届淘宝村高峰论坛 编辑:程序博客网 时间:2024/06/06 04:35
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.
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.
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.
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.
5 6 0 10 60 03 14 36 810 1015 301 52 12 85 540 107 94 10 0 10 100 020 2040 4060 6080 80 5 1015 1025 1035 1045 1055 1065 1075 1085 1095 100
0: 21: 12: 13: 14: 05: 10: 21: 22: 23: 24: 2
As the example illustrates, toys that fall on the boundary of the box are "in" the box.
叉积判断点在线的某一侧
但是数据量太大,需要进行二分
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define MAXN 5010const double eps=1e-8;struct Point{ int x,y; Point(){} Point(int _X,int _Y){ x = _X; y = _Y; }};int ans[MAXN];Point P1[MAXN],P2[MAXN],P;double Cross(Point p1,Point p2,Point p3){ return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);}Point operator - (Point A,Point B){ return Point(A.x-B.x, A.y-B.y);}Point operator + (Point A, Point B){ return Point(A.x+B.x, A.y+B.y);}bool operator == (Point A, Point B){ return (A.x-B.x) == 0 && (A.y-B.y) == 0;}int main(){ int n,m,x1,x2,y1,y2,a,b; //freopen("in.txt","r",stdin); while(scanf("%d",&n)&&n) { memset(ans,0,sizeof(ans)); scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2); for(int i=1;i<=n;i++){ scanf("%d%d",&a,&b); P1[i].x=a, P1[i].y=y1; P2[i].x=b, P2[i].y=y2; } int left,right,mid; for(int i=1;i<=m;i++){ scanf("%d%d",&P.x,&P.y); if(Cross(P1[1],P2[1],P)<=0) ans[0]++; else{ left=1,right=n,mid; while(left<=right) { mid=(left+right)>>1; if(Cross(P1[mid],P2[mid],P)<=0) right=mid-1; else left=mid+1; } ans[right]++; } } for(int i=0;i<=n;i++) printf("%d: %d\n",i,ans[i]); puts(""); } return 0;}
阅读全文
0 0
- poj 2318 叉积判断点在线的某一侧 + 二分
- poj 2318 TOYS 【判断区域里面点的个数】 【二分+叉积判断】
- poj 2398 poj 2318 二分+叉乘 判断 点与线段的位置
- poj2318_TOYS_叉积判断点在线段的哪一侧
- POJ 2318 TOYS 计算几何 判断点在线段的哪一侧
- poj 2398 Toy Storage 【统计相同个数的点的 区域个数】【二分+叉积判断】
- POJ2318->叉积判断点在线段的左右
- POJ 2318 TOYS (判断点与直线关系+二分查找)
- poj2318(叉积判断点的位置+二分查找)
- POJ 2318 点在凸四边形内的判断(叉积+二分)
- poj 2318 点与线位置关系的判断 二分+叉积
- POJ 2318 TOYS [叉积判断+二分查找]【计算几何】
- POJ 2318(点集二分)
- 判断二维点在线段的哪一侧
- poj 2398 叉积判断点位置
- POJ 2318 TOYS(叉积判断点与线段的位置关系)
- POJ 2398 点在凸四边形内的判断(叉积+二分)
- POJ 2318 || POJ 2398判断点和线段的位置
- AES五种加密模式(CBC、ECB、CTR、OCF、CFB)
- java基础之常用快捷键
- 在java代码中,用xslt处理xml文件
- Web报表系统葡萄城报表:矩表(Tablix)
- 每个tab选项卡里都是swiper轮播插件怎样分开控制左右箭头?
- poj 2318 叉积判断点在线的某一侧 + 二分
- Java_基础—HashMap和Hashtable的区别
- hdu 3401 Trade 【单调队列+dp】
- Web报表系统葡萄城报表:报表设计
- Hadoop学习日志之hadoop的组成
- Hadoop-2.8.0之分布式集群(HA架构)搭建
- Win7 Firewall
- 关于XP下,重装VC6.0时出现 “Setup Was Unable to Create a DCOM User Account”问题
- matplotlib scatter 散点图