您的位置:首页 > 其它

Poj 2318 toys (计算几何,叉积)

2015-03-15 21:24 429 查看
题目链接:Poj 2318

直接用叉积做。对于每一件玩具,二分所有的隔间,然后用叉积判断每一个点与这个隔间的关系。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define maxn (5000+10)
int N,M;
int cou[maxn];
struct node{
int x,y;
}S,T,a[maxn];

inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}

void find(int xx,int yy){
int L=0,R=N+1,ans;
while(L<R){
int mid=(L+R)>>1;
node o,p;
o.x=xx-a[mid].x; o.y=yy-S.y;
p.x=xx-a[mid].y; p.y=yy-T.y;
if((o.x*p.y-o.y*p.x)>0){
ans=mid; L=mid+1;
}
else R=mid;
}
cou[ans]++;
}

int main(){
while(scanf("%d",&N)==1){
if(N==0)break;
memset(cou,0,sizeof(cou));
M=read(); S.x=read(); S.y=read(); T.x=read(); T.y=read();
for(int i=1;i<=N;i++){
a[i].x=read(); a[i].y=read();
}
for(int i=1;i<=M;i++){
int xx=read(),yy=read();
find(xx,yy);
}
for(int i=0;i<=N;i++){
printf("%d: %d\n",i,cou[i]);
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: