forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
188 lines (158 loc) · 4.37 KB
/
D.cpp
File metadata and controls
188 lines (158 loc) · 4.37 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define ll long long
#define sqr(x) ((x) * (x))
#define SZ(x) ((int) (x).size())
#define double long double
using namespace std;
const int MN = 2011;
const double EPS = 1e-12;
int cmp(double x, double y) {
if (fabs(x - y) < EPS) return 0;
if (x < y) return -1;
return 1;
}
struct D { // replacement for double
double x;
D() {}
D(double x) : x(x) {}
D operator + (const D& a) const { return D(x+a.x); }
D operator - (const D& a) const { return D(x-a.x); }
D operator * (const D& a) const { return D(x*a.x); }
D operator / (const D& a) const { return D(x/a.x); }
D operator - () const { return D(-x); }
D& operator += (const D& a) { return *this = *this + a; }
D& operator -= (const D& a) { return *this = *this - a; }
D& operator *= (const D& a) { return *this = *this * a; }
D& operator /= (const D& a) { return *this = *this / a; }
bool operator == (const D& a) const { return cmp(x, a.x) == 0; }
bool operator <= (const D& a) const { return cmp(x, a.x) <= 0; }
bool operator >= (const D& a) const { return cmp(x, a.x) >= 0; }
bool operator < (const D& a) const { return cmp(x, a.x) < 0; }
bool operator > (const D& a) const { return cmp(x, a.x) > 0; }
bool operator != (const D& a) const { return cmp(x, a.x) != 0; }
int sign() {
int t = cmp(x, 0);
if (t == 0) return 0;
if (t < 0) return -1;
return 1;
}
friend istream& operator >> (istream& cin, D& x) {
cin >> x.x;
return cin;
}
friend ostream& operator << (ostream& cout, D& x) {
cout << x.x;
return cout;
}
};
struct Fraction {
ll x, y;
Fraction() { x = 0, y = 1; }
Fraction(ll _x, ll _y) {
ll g = __gcd(llabs(_x), llabs(_y));
x = _x / g;
y = _y / g;
if (y < 0) {
x = -x;
y = -y;
}
}
Fraction operator + (const Fraction& a) {
return Fraction(x*a.y + y*a.x, y*a.y);
}
Fraction operator - (const Fraction& a) {
return Fraction(x*a.y - y*a.x, y*a.y);
}
Fraction inverse() {
return Fraction(y, x);
}
Fraction operator * (const Fraction& a) {
return Fraction(x*a.x, y*a.y);
}
D toD() {
return D(x) / D(y);
}
};
bool operator == (const Fraction& a, const Fraction& b) {
if (a.x / a.y != b.x / b.y) return false;
return a.x*b.y == a.y*b.x;
}
bool operator != (const Fraction& a, const Fraction& b) {
return a.x*b.y != a.y*b.x;
}
bool operator < (const Fraction& a, const Fraction& b) {
return a.x*b.y < a.y*b.x;
}
struct Point {
Fraction x, y;
Point() {}
Point(Fraction x, Fraction y) : x(x), y(y) {}
Point operator - (const Point& a) {
return Point(x-a.x, y-a.y);
}
};
bool operator == (const Point& a, const Point& b) {
return a.x == b.x && a.y == b.y;
}
bool operator < (const Point& a, const Point& b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
int n;
struct Line {
ll a, b, c;
void read() {
cin >> a >> b >> c;
}
} lines[MN];
Point a[MN];
ll C2(ll x) {
return x * (x-1LL) / 2;
}
int main() {
while (cin >> n) {
FOR(i,1,n) lines[i].read();
FOR(i,1,n) {
ll t = sqr(lines[i].a) + sqr(lines[i].b);
a[i].x = Fraction(-lines[i].a * lines[i].c, t);
a[i].y = Fraction(-lines[i].b * lines[i].c, t);
}
ll res = 0;
Fraction zero(0, 1);
Fraction one(1, 1);
FOR(i,1,n) {
int same = 0;
map< pair<D, D>, ll > cnt;
FOR(j,i+1,n) {
if (a[i] == a[j]) {
++same;
}
else {
D dx = a[j].x.toD() - a[i].x.toD();
D dy = a[j].y.toD() - a[i].y.toD();
if (dx == 0) dy = 1;
else if (dy == 0) dx = 1;
else {
D len = hypot(dx.x, dy.x);
dx /= len;
dy /= len;
if (dx < 0) dx = -dx, dy = -dy;
}
cnt[ make_pair(dx, dy) ] += 1;
}
}
res += C2(same);
for(auto p : cnt) {
res += C2(p.second);
res += same * p.second;
}
}
cout << res << endl;
}
}