您的位置:首页 > 其它

POJ 2318 TOYS 几何题 基础

2015-09-05 22:28 337 查看
题意:给你一个矩形,并给你一些线分割这个矩形。有一些玩具,给出玩具坐标。求每个区域有多少个玩具。

方法:利用叉积判断玩具的位置。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int N=5005;
struct node{
int x,y;
node(int _x=0,int _y=0):x(_x),y(_y){}
node operator - (node B){
return node(x-B.x,y-B.y);
}
int operator * (node B){
return x*B.y-y*B.x;
}
}a
,b
,A,B,C;
int n,m;
int X1,X2,Y1,Y2;
int ans
;
void solve(){
for(int i=0;i<n;i++){
if((a[i]-b[i])*(C-b[i])>0){
ans[i]++;
return;
}
}
ans
++;
}
void work(){
while(~scanf("%d",&n)&&n){
scanf("%d%d%d%d%d",&m,&X1,&Y1,&X2,&Y2);
A.y=Y1;B.y=Y2;
for(int i=0;i<n;i++){
scanf("%d%d",&A.x,&B.x);
a[i]=A;b[i]=B;
}
memset(ans,0,sizeof(ans));
for(int i=0;i<m;i++){
scanf("%d%d",&C.x,&C.y);
solve();
}
for(int i=0;i<=n;i++)
printf("%d: %d\n",i,ans[i]);
printf("\n");
}
}
int main(){
//freopen("data.txt","r",stdin);
work();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: