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>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
vector<pair<double,double>> seg;
int n, h;
double findp(int x1, int y1, int x2, int y2){
return (x1*y2-y1*x2+x2*h-x1*h)/(y2-y1);
}
signed main(){
fastio
cin >> n >> h;
vector<pair<int,int>> v;
for(int i = 0;i < n;i++){
int x,y;
cin >> x >> y;
v.push_back({x,y});
}
for(int i = 2;i < n-1;i+=2){
seg.push_back({findp(v[i-1].first,v[i-1].second,v[i].first,v[i].second),findp(v[i].first,v[i].second,v[i+1].first,v[i+1].second)});
}
sort(seg.begin(),seg.end(),[&](pair<int,int> a, pair<int,int> b){
return a.second < b.second;
});
int lst = -1e18, ans = 0;
for(auto [a,b] : seg){
if(lst >= a) continue;
else lst = b, ans++;
}
cout << ans << "\n";
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:30:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for(auto [a,b] : seg){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |