POJ 2318
链接(http://poj.org/problem?id=2318)
图论入门之判断直线与点的位置关系
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x1,x2,y1,y2;
}p[5050];
bool is_in(int x,int y,int a)
{
int x1=p[a].x1;
int x2=p[a].x2;
int y1=p[a].y1;
int y2=p[a].y2;
int ans=((x1-x)*(y2-y)-(y1-y)*(x2-x));
return ans>0?true:false;
}
int main()
{
int n,m,xl,yl,xr,yr;
while(scanf("%d",&n),n)
{
scanf("%d%d%d%d%d",&m,&xl,&yl,&xr,&yr);
p[0].x1=xl;
p[0].x2=xl;
p[n+1].x1=xr;
p[n+1].x2=xr;
for(int i=1;i<=n;i++)
scanf("%d%d",&p[i].x1,&p[i].x2);
for(int i=0;i<=n+1;i++)
{
p[i].y1=yl;
p[i].y2=yr;
}
int cnt[5050];
for(int i = 0 ; i < 5050 ; i++)
cnt[i] = 0;
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
int temp=0;
while(is_in(x,y,temp))
temp++;
//case temp fasle, use temp-1
cnt[temp-1]++;
}
for(int i=0;i<=n;i++)
printf("%d: %d
",i,cnt[i]);
cout << endl;
}
return 0;
}