-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem_11_D.cpp
119 lines (92 loc) · 1.83 KB
/
Problem_11_D.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
// Problem_11_D.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms.
//
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
class vec2 {
int x;
int y;
public:
vec2() {
x = -1;
y = -1;
}
vec2(int myx, int myy) {
x = myx;
y = myy;
}
vec2 sub(vec2 other) {
return vec2(x - other.x, y - other.y);
}
bool isParallel(vec2 otherDir) {
return x * otherDir.y - otherDir.x * y == 0;
}
bool isZero() {
return x == 0 && y == 0;
}
};
class line {
vec2 start;
vec2 end;
vec2 dir;
public:
line(vec2 a, vec2 b) {
start = a;
end = b;
dir = end.sub(start);
}
bool isParallel(line other) {
return dir.isParallel(other.dir);
}
bool isSame(line other) {
if (!isParallel(other)) return false;
vec2 newdir = other.start.sub(start);
if (newdir.isZero()) newdir = other.start.sub(end);
return newdir.isParallel(dir);
}
};
int main() {
int w;
int n;
cin >> w >> n;
vector<line> lines;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
vec2 start = vec2(x, y);
cin >> x >> y;
vec2 end = vec2(x, y);
line tmp_line = line(start, end);
bool addLine = true;
for (int j = 0; j < lines.size(); j++) {
if (tmp_line.isSame(lines[j])) {
addLine = false;
break;
}
}
if (addLine) lines.push_back(tmp_line);
}
bool allParallel = true;
for (int i = 1; i < lines.size(); i++) {
if (!lines[0].isParallel(lines[i])) {
allParallel = false;
break;
}
}
int cur = 0, add = 0;
if (allParallel) {
cur = lines.size() + 1;
add = cur;
} else {
cur = 2 * lines.size();
add = 2;
}
int res = 0;
if (add < 2) add = 2;
while (cur < w) {
res++;
cur += add;
add = 2;
}
cout << res << endl;
}