#include <iostream>
#include <cstdio>
using namespace std;
struct node
{
double xs, ys;
double xe, ye;
}p[231];
double Ijs(int i, double x, double y)
{
return (p[i].xs-x) * (p[i].ye-y) - (p[i].ys-y) * (p[i].xe-x);
}
bool Iseg(int i, int j)
{
if(min(p[i].xs, p[i].xe) <= max(p[j].xs, p[j].xe) &&
min(p[i].ys, p[i].ye) <= max(p[j].ys, p[j].ye) &&
min(p[j].xs, p[j].xe) <= max(p[i].xs, p[i].xe) &&
min(p[j].ys, p[j].ye) <= max(p[i].ys, p[i].ye) &&
Ijs(i, p[j].xs, p[j].ys) * Ijs(i, p[j].xe, p[j].ye) <= 0 &&
Ijs(j, p[i].xs, p[i].ys) * Ijs(j, p[i].xe, p[i].ye) <= 0)
return true;
return false;
}
int main()
{
int n;
while(scanf("%d", &n) != EOF && n)
{
for(int i = 0; i < n; i++)
scanf("%lf%lf%lf%lf", &p[i].xs, &p[i].ys, &p[i].xe, &p[i].ye);
int sum = 0;
for(int i = 0; i < n-1; i++)
for(int j = i+1; j < n; j++)
if(Iseg(i, j)) sum++;
cout << sum << endl;
}
}
hdu 1086 You can Solve a Geometry Problem too 线段相交
最新推荐文章于 2021-05-30 09:27:49 发布