poj-2318 toys 计算几何 点与线的关系

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;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值