poj-2318
计算几何问题
叉积 点与直线的关系
叉积为负数在直线左边
为正在右边
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxx=1e5+10;
struct point{
int x,y;
point(){
}
point(int _x,int _y){
x=_x;
y=_y;
}
};
struct line{
point x,y;
line(){
}
line(point _x,point _y){
x=_x;
y=_y;
}
}l[maxx];
int mul(point x0,point x1,point x2){ //叉积
return (x1.x-x0.x)*(x2.y-x0.y)-(x1.y-x0.y)*(x2.x-x0.x);
}
int main(){
int n,ans[maxx];
int ff=0;
while(cin>>n&&n){
if(!ff) ff=1;
else cout<<endl;
int m,x1,y1,x2,y2;
cin>>m>>x1>>y1>>x2>>y2;
for(int i=0;i<n;i++){
int u,v;cin>>u>>v;
l[i]=line(point(u,y1),point(v,y2));
}
l[n]=line(point(x2,y1),point(x2,y2));
memset(ans,0,sizeof(ans));
point p;
for(int i=0;i<m;i++){
int x,y;cin>>x>>y;
p=point(x,y);
int low=0,high=n,tmp;
while(low<=high){
int mid=(low+high)/2;
if(mul(p,l[mid].x,l[mid].y)<0){
tmp=mid;
high=mid-1;
}
else low=mid+1;
}
ans[tmp]++;
}
for(int i=0;i<=n;++i)
printf("%d: %d\n",i,ans[i]);
}
return 0;
}