设点为p0, 线段为p2-p1;
则向量p1-p0,和p2-p0求叉积
如果大于零则p0在线段左侧,小于0在右侧;
PxQ>0表示P在Q顺时针方向,<0在逆时针,=0共线;
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
const double eps=1e-8;
const double inf=1e20;
const double pi=acos(-1.0);
const int maxp=1010;
int sgn(double x)
{
if(fabs(x)<eps)return 0;
if(x<0)return -1;
else return 1;
}
inline double sqr(double x){return x*x;}
struct Point
{
double x,y;
Point(){}
Point (double _x,double _y)
{
x=_x;
y=_y;
}
double operator ^(const Point &b)const{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const{
return x*b.x+y*b.y;
}
Point operator-(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
};
struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s=_s;
e=_e;
}
int sercrossseg(Line v)
{
int d1=sgn((e-s)^(v.s-s));
int d2=sgn((e-s)^(v.e-s));
int d3=sgn((v.e-v.s)^(s-v.s));
int d4=sgn((v.e-v.s)^(e-v.s));
if((d1^d2)==-2&&(d3^d4)==-2)return 2;
return (d1==0&&sgn((v.s-s)*(v.s-e))<=0)||(d2==0&&sgn((v.e-s)*(v.e-e))<=0)||(d3==0&&sgn((s-v.s)*(s-v.e))<=0)||(d4==0&&sgn((e-v.s)*(e-v.e))<=0);
}
}L[11111];
int ans[111111];
int mult(Point p0,Point p1,Point p2)
{
return (p1-p0)^(p2-p0);
}
int main()
{
int n,m,x1,y1,x2,y2;
while(~scanf("%d",&n)&&n)
{
memset(ans,0,sizeof ans);
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
int xx,xxx;
for(int i=0;i<n;i++)
{
scanf("%d%d",&xx,&xxx);
L[i]=Line(Point(xx,y1),Point(xxx,y2));
}
L[n]=Line(Point(x2,y1),Point(x2,y2));
for(;m;m--)
{
int x,y;
scanf("%d%d",&x,&y);
int l=0,r=n;
int num;
while(l<=r)
{
int mid=(l+r)>>1;
if(mult(Point(x,y),L[mid].s,L[mid].e)<0)
{
r=mid-1;
num=mid;
}
else l=mid+1;
}
ans[num]++;
}
for(int i=0;i<=n;i++)
{
printf("%d: %d\n",i,ans[i]);
}
printf("\n");
}
}