#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct Point{
long long x, y;
};
int n, ans;
Point arr[N];
long double l[N], r[N], h, mx;
vector<pair<long double, long double>> v;
int orient(Point a, Point b, Point c){
long long diff = (c.y - b.y) * (b.x - a.x) - (b.y - a.y) * (c.x - b.x);
if(diff < 0) return 1;
else if(diff > 0) return -1;
else return 0;
}
vector<Point> hull;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> h;
for(int i = 1; i <= n; i++) cin >> arr[i].x >> arr[i].y;
hull.push_back(arr[1]), hull.push_back(arr[2]);
for(int i = 3; i <= n - 2; i += 2){
while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i]) != 1) hull.pop_back();
l[i] = arr[i].x + ((h - arr[i].y) / (hull.back().y - arr[i].y)) * (hull.back().x - arr[i].x);
hull.push_back(arr[i]);
while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i + 1]) != 1) hull.pop_back();
hull.push_back(arr[i + 1]);
}
hull.clear();
hull.push_back(arr[n]), hull.push_back(arr[n - 1]);
for(int i = n - 2; i >= 3; i -= 2){
while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i]) != -1) hull.pop_back();
r[i] = arr[i].x + ((h - arr[i].y) / (hull.back().y - arr[i].y)) * (hull.back().x - arr[i].x);
hull.push_back(arr[i]);
while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i - 1]) != -1) hull.pop_back();
hull.push_back(arr[i - 1]);
}
for(int i = 3; i <= n - 2; i += 2) v.push_back({r[i], l[i]});
sort(v.begin(), v.end());
mx = v[0].first, ans = 1;
for(int i = 1; i < v.size(); i++){
if(v[i].second < mx) continue;
else ans++, mx = v[i].first;
}
cout << ans;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1236 KB |
Output is correct |
2 |
Correct |
3 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Incorrect |
28 ms |
8140 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1236 KB |
Output is correct |
2 |
Correct |
3 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Incorrect |
28 ms |
8140 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |