雅礼2017国庆1-1
题解懒得写了...题目虽然不难,但是std的写法是最方便的,于是我就学了一遍。。。
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #define N 200005 using namespace std; struct p{int x,y;}a[N]; bool cmp(p a,p b){return a.x<b.x;} int n,ans=0; int main() { freopen("clique.in","r",stdin); freopen("clique.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++) { int x,w; scanf("%d%d",&x,&w); a[i].x=x-w; a[i].y=x+w; } sort(a+1,a+n+1,cmp); int k=0; for(int i=1;i<=n;i++) { while(k && a[k].y>a[i].y)k--; a[++k]=a[i]; } n=k; for(int i=1,e=-2000000005;i<=n;i++) if(a[i].x>=e){e=a[i].y;ans++;} printf("%d",ans); fclose(stdin);fclose(stdout); //system("pause"); return 0; }