http://icpc.upc.edu.cn/problem.php?cid=1762&pid=2
#include<bits/stdc++.h> using namespace std; struct node{ double x; double y; }; struct Line{ node s,e; }; Line l[110]; bool judge(node a,node b,node c,node d) { if(min(a.x,b.x) <= max(c.x,d.x) && min(c.x,d.x) <= max(a.x,b.x) && min(a.y,b.y) <= max(c.y,d.y) &&min(c.y,d.y)<=max(a.y,b.y)) { double u,v,w,z; u=(c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); v=(d.x-a.x)*(b.y-a.y)-(b.x-a.x)*(d.y-a.y); w=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y); z=(b.x-c.x)*(d.y-c.y)-(d.x-c.x)*(b.y-c.y); return (u*v<=0.00000001 && w*z<=0.00000001); } return false; } int n; int main() { scanf("%d",&n); int ans=0; for(int i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&l[i].s.x,&l[i].s.y,&l[i].e.x,&l[i].e.y); for(int j=1;j<i;j++) { ans+=judge(l[j].s,l[j].e,l[i].s,l[i].e); } } cout<<ans<<endl; return 0; }