-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunique line.cpp
53 lines (50 loc) · 1.23 KB
/
unique line.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
#include<bits/stdc++.h>
#define PB push_back
#define MK make_pair
using namespace std;
typedef pair<int,int> pii;
struct line{
int a,b,c;
bool operator< (const line &l)const{
if(a==l.a){
if(b==l.b){
return c<l.c;
}
return b<l.b;
}
return a<l.a;
}
};
int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}
int main(){
int teestcase;
cin>>teestcase;
while(teestcase--){
int n;
cin>>n;
vector<pii>loc;
set<line>line_set;
for(int i=0,x,y;i<n;i++){
cin>>x>>y;
pii tmp = MK(x,y);
for(int ptr = 0; ptr<loc.size();ptr++){
int x1 = loc[ptr].first,y1 = loc[ptr].second , x2 = x , y2 = y,a,b,c;
a = y2-y1;
b = y1*x2-y2*x1;
c = x2-x1;
int divider = (gcd(a,gcd(b,c)));
a/=divider,b/=divider,c/=divider;
if(a<0){
a*=-1,b*=-1,c*=-1;
}
line_set.insert({a,b,c});
}
loc.PB(tmp);
}
cout<<line_set.size()<<endl;
}
return 0;
}