-
Notifications
You must be signed in to change notification settings - Fork 0
/
finding_lines.cpp
51 lines (49 loc) · 1.18 KB
/
finding_lines.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
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main () {
vector <pair <lli, lli>> points;
pair <lli,lli> P0, P1;
bool found = false;
int i, n, p, res, r0, r1;
cin >> n >> p;
for (i = 0; i < n; i++) {
cin >> P0.first >> P0.second;
points.push_back(P0);
}
for (i = 0; i < 250; i++) {
// take a random P_0 P_1
r0 = rand() % n;
r1 = r0;
while (r0 == r1 & n != 1) {
r1 = rand() % n;
}
P0 = points[r0];
P1 = points[r1];
// check all the points
res = 0;
// non vertical case
if (P0.first != P1.second) {
for (int j = 0; j < n; j++ ) {
if ( (points[j].second - P1.second)*(P1.first - P0.first) ==
(P1.second - P0.second)*(points[j].first - P1.first) ) {
res++;
}
}
}
// vertical case
else {
for (int j = 0; j < n; j++ ) {
if (points[j].first == P0.first) res++;
}
}
if ( ((float) res / (float) n)*100 >= (float) p ) {
cout << "possible";
found = true;
break;
}
//cout << r0 << " " << r1 << " " << res << "\n";
}
if (found == false) cout << "impossible";
return 0;
}