HDU 1086 You can Solve a Geometry Problem too(水题)

来源:互联网 发布:linux apt安装 编辑:程序博客网 时间:2024/05/21 19:44

题意:给你几条线段统计有几个交点

#include<iostream>using namespace std;struct point{    double x,y;};struct line{    point st,en;}l[101];double cross(point a,point b,point c)///叉积{    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}int main(){    int n,i,j,k;    while(cin>>n&&n)    {        for(i=0;i<n;i++)        {            cin>>l[i].st.x>>l[i].st.y>>l[i].en.x>>l[i].en.y;        }        k=0;        for(i=0;i<n;i++)            for(j=i+1;j<n;j++)        {            if(cross(l[i].st,l[i].en,l[j].st)*cross(l[i].st,l[i].en,l[j].en)<1e-10&&cross(l[j].st,l[j].en,l[i].st)*cross(l[j].st,l[j].en,l[i].en)<1e-10)///相互跨立即相交            k++;        }        cout<<k<<endl;    }}


0 0