#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 7;
struct Point{
int x, y;
Point(int _x = 0, int _y = 0){
x = _x;
y = _y;
}
};
struct Line{
ll a, b, c;
Line(ll _a, ll _b, ll _c){
a = _a;
b = _b;
c = _c;
}
Line(const Point &A, const Point &B){
a = A.y - B.y;
b = B.x - A.x;
c = (ll) A.x * B.y - (ll) A.y * B.x;
}
};
int n, h;
Point p[N];
long double findXCoor(const Line &d1, const Line &d2){
ll D = d1.a * d2.b - d2.a * d1.b;
ll Dx = -d1.c * d2.b + d2.c * d1.b;
ll Dy = -d1.a * d2.c + d2.a * d1.c;
assert(D != 0);
return (long double) Dx / D;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> h;
for(int i = 1; i <= n; i++)
cin >> p[i].x >> p[i].y;
Line d(0, 1, -h);
vector<pair<long double, long double>> segments;
for(int i = 3; i <= n - 2; i += 2){
//cerr << findXCoor(Line(p[i - 1], p[i]), d) << ' ' << findXCoor(Line(p[i], p[i + 1]), d) << endl;
segments.push_back({findXCoor(Line(p[i - 1], p[i]), d), findXCoor(Line(p[i], p[i + 1]), d)});
}
sort(segments.begin(), segments.end(), [](const pair<long double, long double> &a, const pair<long double, long double> &b){
return a.second < b.second;
});
int answer = 0;
long double lastX = -1e18;
for(auto p : segments)
if (lastX < p.first){
answer++;
lastX = p.second;
}
cout << answer;
return 0;
}
Compilation message
Main.cpp: In function 'long double findXCoor(const Line&, const Line&)':
Main.cpp:36:8: warning: unused variable 'Dy' [-Wunused-variable]
36 | ll Dy = -d1.a * d2.c + d2.a * d1.c;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8684 KB |
Output is correct |
2 |
Correct |
9 ms |
8684 KB |
Output is correct |
3 |
Correct |
8 ms |
8684 KB |
Output is correct |
4 |
Correct |
30 ms |
11496 KB |
Output is correct |
5 |
Correct |
30 ms |
11624 KB |
Output is correct |
6 |
Correct |
33 ms |
11752 KB |
Output is correct |
7 |
Correct |
251 ms |
34908 KB |
Output is correct |
8 |
Correct |
295 ms |
36956 KB |
Output is correct |
9 |
Correct |
285 ms |
38656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8300 KB |
Output is correct |
2 |
Incorrect |
6 ms |
8300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8684 KB |
Output is correct |
2 |
Correct |
9 ms |
8684 KB |
Output is correct |
3 |
Correct |
8 ms |
8684 KB |
Output is correct |
4 |
Correct |
30 ms |
11496 KB |
Output is correct |
5 |
Correct |
30 ms |
11624 KB |
Output is correct |
6 |
Correct |
33 ms |
11752 KB |
Output is correct |
7 |
Correct |
251 ms |
34908 KB |
Output is correct |
8 |
Correct |
295 ms |
36956 KB |
Output is correct |
9 |
Correct |
285 ms |
38656 KB |
Output is correct |
10 |
Correct |
6 ms |
8300 KB |
Output is correct |
11 |
Incorrect |
6 ms |
8300 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |