forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripart.cpp
72 lines (72 loc) · 1.3 KB
/
tripart.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
// 2008-07-23
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
using namespace std;
struct Triangle
{
long double l1;
long double l2;
Triangle(){}
Triangle(long double a,long double b,long double c)
{
if (a>b)
swap(a,b);
if (b>c)
swap(b,c);
if (a>b)
swap(a,b);
l1=b/a;
l2=c/a;
}
};
bool equ(long double x,long double y)
{
return x>=y&&x-y<1e-8||y>=x&&y-x<1e-8;
}
bool below(long double x,long double y)
{
return !equ(x,y)&&x<y;
}
bool operator<(Triangle t1,Triangle t2)
{
if (below(t1.l1,t2.l1))
return true;
else if (equ(t1.l1,t2.l1))
if (below(t1.l2,t2.l2))
return true;
else
return false;
else
return false;
}
int main()
{
int N;
scanf("%d",&N);
long double a,b,c;
while (N--)
{
set<Triangle> S;
stack<Triangle> s;
scanf("%Lf %Lf %Lf",&a,&b,&c);
s.push(Triangle(a,b,c));
while (!s.empty())
{
Triangle T=s.top();
s.pop();
if (S.find(T)!=S.end())
continue;
else
S.insert(T);
long double cos1=(1.0L+T.l2*T.l2-T.l1*T.l1)/(2.0L*T.l2);
long double cos2=(T.l1*T.l1+T.l2*T.l2-1.0L)/(2.0L*T.l1*T.l2);
s.push(Triangle(1.0L,T.l2/2.0L,sqrt(1.0L+T.l2*T.l2/4.0L-T.l2*cos1)));
s.push(Triangle(T.l1,T.l2/2.0L,sqrt(T.l1*T.l1+T.l2*T.l2/4.0L-T.l1*T.l2*cos2)));
}
printf("%d\n",S.size());
}
return 0;
}