给出两个点,确定一条线段AB
给出n条直线,求上面那条线段AB与这n条直线有几个交点
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
struct node
{
int x,y,z;
};
node tm[1005];
int main()
{
int ok=0;
int stx,sty,edx,edy;
int n,x,y,z;
double a,b,c;
scanf("%d%d",&stx,&sty);
scanf("%d%d",&edx,&edy);
int chuizhi=0;
double xielv;
if (stx==edx)
{
chuizhi=1;
}
else
{
xielv=(double)(sty-edy)/(double)(stx-edx);
}
int i;
scanf("%d",&n);
int ans=0;
for (i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
a=x;
b=y;
c=z;
if (b==0)
{
if (chuizhi) continue;
else
{
double xx=-(c/a);
if ((xx>=stx&&xx<=edx) ||(xx>=edx&&xx<=stx) )
ans++;
}
}
else
{
double xie=-(a/b);
if (chuizhi)
{
double yy=-(a*stx+c)/b;
if ((yy>=sty&&yy<=edy) ||(yy>=edy&&yy<=sty))
ans++;
}
else
{
if (xielv==xie) continue;
else
{
double xx=-(c+b*sty-b*stx*xielv)/(a+b*xielv);
if ((xx>=stx&&xx<=edx) ||(xx>=edx&&xx<=stx) )
ans++;
}
}
}
}
printf("%d\n",ans);
return 0;
}