CF545C Woodcutters
贪心,能倒就倒,能往左就往左实在不行往右
因为倒不倒都只影响下一棵树
大不了下一个不倒还对后面更优。
#include<bits/stdc++.h>
using namespace std;
#define orz cout<<"lyakioi!!!!!!!!!!!!!!!!!"<<endl
inline int r(){int s=0,k=1;char c=getchar();while(!isdigit(c)){if(c=='-')k=-1;c=getchar();}while(isdigit(c)){s=s*10+c-'0';c=getchar();}return s*k;}
int n,lst=-1e9-5,ans=0;
struct node
{
int x,h;
}a[1000001];
bool cmp(node x,node y)
{
return x.x<y.x;
}
int main()
{
n=r();
for(int i=1;i<=n;i++)
{
a[i].x=r();a[i].h=r();
}
sort(a+1,a+n+1,cmp);
a[n+1].x=2e9+100;
for(int i=1;i<=n;i++)
{
if(a[i].x-lst>a[i].h)
{
lst=a[i].x;
ans++;
}
else if(a[i+1].x>a[i].h+a[i].x)
{
lst=a[i].x+a[i].h;
ans++;
}
else lst=a[i].x;
}
cout<<ans;
}
本文来自博客园,作者:lei_yu,转载请注明原文链接:https://www.cnblogs.com/lytql/p/15224377.html