This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
if(n == 3){
cout << 0;
return 0;
}
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 (stderr)
Main.cpp: In function 'int main()':
Main.cpp:77: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]
77 | for(int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |