/**
* author: wxhtzdy
* created: 02.07.2022 16:49:56
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, h;
cin >> n >> h;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
vector<pair<int, int>> ev;
for (int i = 2; i < n - 1; i += 2) {
ev.emplace_back(i, 0);
ev.emplace_back(i, 1);
}
sort(ev.begin(), ev.end(), [&](pair<int, int> a, pair<int, int> b) {
double xa = x[a.first];
double xb = x[b.first];
double pa = (a.second == 0 ? x[a.first - 1] : x[a.first + 1]) - x[a.first];
double pb = (b.second == 0 ? x[b.first - 1] : x[b.first + 1]) - x[b.first];
double qa = (a.second == 0 ? y[a.first - 1] : y[a.first + 1]) - y[a.first];
double qb = (b.second == 0 ? y[b.first - 1] : y[b.first + 1]) - y[b.first];
double new_xa = xa + h * ((double) pa / (double) qa);
double new_xb = xb + h * ((double) pb / (double) qb);
// xa + h * (pa / qa) < xb + h * (pb / qb)
// xa - xb < h * (pb / qb - pa / qa)
// (xa - xb) / h < pb / qb - pa / qa
// (xa - xb) / h < (pb * qa - pa * qb) / qa * qb
// (xa - xb) * (qa * qb) < (pb * qa - pa * qb) * h
long long dx = xa - xb;
long long pq = qa * 1LL * qb;
long long qp = pb * 1LL * qa - pa * 1LL * qb;
long long L = dx * pq;
long long R = qp * h;
if (new_xa == new_xb) {
return a.second < b.second;
} else {
return new_xa < new_xb;
}
});
int ans = 0;
set<int> alive;
for (auto& e : ev) {
if (e.second == 0) {
alive.insert(e.first);
} else {
if (alive.find(e.first) == alive.end()) {
continue;
}
alive.clear();
ans += 1;
}
}
cout << ans << '\n';
return 0;
}
Compilation message
Main.cpp: In lambda function:
Main.cpp:41:15: warning: unused variable 'L' [-Wunused-variable]
41 | long long L = dx * pq;
| ^
Main.cpp:42:15: warning: unused variable 'R' [-Wunused-variable]
42 | long long R = qp * h;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |