#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=1e6+5;
bool cmp(pair<double,double> a, pair<double,double> b){
return a.sc<b.sc;
}
int x[N],y[N];
double slope(int a, int b){
return (y[b]-y[a])/(x[b]-x[a]+0.0);
}
int cross(pair<int,int> a, pair<int,int> b){
return a.fr*b.sc-a.sc*b.fr;
}
int cross(int a, int b, int c){
return cross(mp(x[b]-x[a],y[b]-y[a]),mp(x[c]-x[a],y[c]-y[a]));
}
void solve(){
int n,h;cin>>n>>h;
for(int i=0;i<n;i++)
cin>>x[i]>>y[i];
vector<double> l(n),r(n);
vector< pair<double,double> > v;
deque<int> st;
st.pb(0);
for(int i=1;i<n;i++){
while(st.size()>1 && cross(st[st.size()-2],st.back(),i)>0)
st.pop_back();
if(i%2==0){
//if(slope(i,st.back())==0) l[i]=-INF;
/*cout<<i<<':';
for(auto it: st)
cout<<' '<<it;
cout<<endl;*/
l[i]=x[st.back()]+(h-y[st.back()])/slope(i,st.back());
}
st.push_back(i);
}
while(!st.empty()) st.pop_back();
st.pb(n-1);
for(int i=n-2;i>=0;i--){
while(st.size()>1 && cross(st[st.size()-2],st.back(),i)<0)
st.pop_back();
if(i%2==0){
//if(slope(st.back(),i)==0) r[i]=INF;
r[i]=x[i]+(h-y[i])/slope(st.back(),i);
}
st.push_back(i);
}
/*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);
r[i]=x[i-1]+(h-y[i-1])/slope;
//v.pb(mp(l[i],r[i]));
}*/
//cout<<fixed<<setprecision(3);
for(int i=2;i<n-1;i+=2) v.pb(mp(l[i],r[i]));
sort(all(v), cmp);
/*for(int i=0;i<n;i++)
cout<<l[i]<<' '<<r[i]<<endl;*/
int ans=1;
double 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(auto it: v)
cout<<it.fr<<' '<<it.sc<<endl;*/
cout<<ans;
}
int main(){
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:72: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]
72 | for(int i=1;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2904 KB |
Output is correct |
2 |
Correct |
6 ms |
2908 KB |
Output is correct |
3 |
Correct |
6 ms |
2748 KB |
Output is correct |
4 |
Correct |
42 ms |
9676 KB |
Output is correct |
5 |
Correct |
50 ms |
9680 KB |
Output is correct |
6 |
Correct |
50 ms |
9688 KB |
Output is correct |
7 |
Correct |
462 ms |
42184 KB |
Output is correct |
8 |
Correct |
494 ms |
47548 KB |
Output is correct |
9 |
Correct |
512 ms |
48580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2904 KB |
Output is correct |
2 |
Correct |
6 ms |
2908 KB |
Output is correct |
3 |
Correct |
6 ms |
2748 KB |
Output is correct |
4 |
Correct |
42 ms |
9676 KB |
Output is correct |
5 |
Correct |
50 ms |
9680 KB |
Output is correct |
6 |
Correct |
50 ms |
9688 KB |
Output is correct |
7 |
Correct |
462 ms |
42184 KB |
Output is correct |
8 |
Correct |
494 ms |
47548 KB |
Output is correct |
9 |
Correct |
512 ms |
48580 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |