#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define mp make_pair
#define ll long long
const ll INF=1e18,N=2e5+5;
bool cmp(pair<double,double> a, pair<double,double> b){
return a.sc<b.sc;
}
void solve(){
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<double> l(n),r(n);
vector< pair<double,double> > v;
stack<int> st;
for(int i=2;i<n-1;i+=2){
double slope=(y[i+1]-y[i])/(x[i+1]-x[i]+0.0);
r[i]=x[i]+(h-y[i])/slope;
slope = (y[i]-y[i-1])/(x[i]-x[i-1]+0.0);
l[i]=x[i-1]+(h-y[i-1])/slope;
v.pb(mp(l[i],r[i]));
}
sort(all(v), cmp);
int ans=1;
double lx=v[0].fr,rx=v[0].sc;
for(int i=1;i<v.size();i++){
if(v[i].fr>rx+1e-9){
rx=v[i].sc;
ans++;
}
}
/*cout<<fixed<<setprecision(3);
for(int i=0;i<n;i++)
cout<<l[i]<<' '<<r[i]<<endl;*/
cout<<ans;
}
int main(){
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i=1;i<v.size();i++){
| ~^~~~~~~~~
Main.cpp:32:9: warning: unused variable 'lx' [-Wunused-variable]
32 | double lx=v[0].fr,rx=v[0].sc;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
7 ms |
856 KB |
Output is correct |
4 |
Correct |
41 ms |
4556 KB |
Output is correct |
5 |
Correct |
44 ms |
4696 KB |
Output is correct |
6 |
Correct |
49 ms |
4808 KB |
Output is correct |
7 |
Correct |
390 ms |
39072 KB |
Output is correct |
8 |
Correct |
447 ms |
39780 KB |
Output is correct |
9 |
Correct |
482 ms |
40412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
7 ms |
856 KB |
Output is correct |
4 |
Correct |
41 ms |
4556 KB |
Output is correct |
5 |
Correct |
44 ms |
4696 KB |
Output is correct |
6 |
Correct |
49 ms |
4808 KB |
Output is correct |
7 |
Correct |
390 ms |
39072 KB |
Output is correct |
8 |
Correct |
447 ms |
39780 KB |
Output is correct |
9 |
Correct |
482 ms |
40412 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |