-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU1086.cpp
121 lines (111 loc) · 2.11 KB
/
HDU1086.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
ID: mfs6174
PROG: 判断线段相交
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define sf scanf
using namespace std;
//ifstream inf("ti.in");
//ofstream ouf("ti.out");
const int maxlongint=2147483647;
const double INF=1e200;
const double Ling=1e-8;
bool fail;
struct P
{
double x;
double y;
//constructor
P(double a=0, double b=0)
{ x=a; y=b;}
P operator+(const P &b) const
{
return P(x + b.x, y + b.y);
}
P operator - (const P &b) const
{
return P(x - b.x, y - b.y);
}
bool operator<(const P &b) const//a在b逆时针
{
return x * b.y < y * b.x;
}
double operator ^ (const P &b) const //aXb
{
return x*b.y-b.x*y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
struct SEG
{
P s,e;
SEG(P a=P(0,0), P b=P(0,0)) { s=a; e=b;}
void input()
{
s.input();e.input();
}
};
inline int cwz(double x)
{
if (abs(x)<Ling)
return 0;
else
return (x>0)?1:-1;
}
inline double cha(P a,P b,P c)
{
return (b-a)^(c-a);
}
inline P lcp(P aa, P ad, P ba, P bd)//返回fail如果true说明平行或重合再交叉相减叉积即可
{ // 求直线交点
ad = ad - aa;
bd = bd - ba;
double tmp = bd ^ ad;
fail=false;
if (cwz(tmp)==0)
{
fail=true;
return P(0,0);
}
else
return P((ad.x * bd.x * (ba.y - aa.y) + aa.x * bd.x * ad.y - ba.x * ad.x * bd.y) / tmp,
(ad.y * bd.y * (aa.x - ba.x) + ba.y * ad.y * bd.x - aa.y * bd.y * ad.x) / tmp);
}
inline bool os(SEG &l,P &p)
{
return( (cwz(cha(l.s,l.e,p))==0) &&( ( cwz((p.x-l.s.x)*(p.x-l.e.x))<=0 )&&( cwz((p.y-l.s.y)*(p.y-l.e.y))<=0 ) ) );
}
int i,j,t,n,m,mm;
SEG shu[110];
P rr;
int main()
{
freopen("ti.in","r",stdin);
while (scanf("%d",&n)!=EOF&&n)
{
mm=0;
for (i=1;i<=n;i++)
shu[i].input();
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
{
rr=lcp(shu[i].s,shu[i].e,shu[j].s,shu[j].e);
if (!fail)
if (os(shu[i],rr)&&os(shu[j],rr))
mm++;
}
cout<<mm<<endl;
}
return 0;
}