标签:span struct sort ++ amp using int == bool
题解:
其实只要排个序贪心一下就好了。。。代码600B不到。。。
代码:
#include<bits/stdc++.h> using namespace std; const int N=2e5+10,INF=1e9; int n,x,w; struct node { int l,r; }a[N]; bool cmp(node a,node b) { if (a.r==b.r)return a.l<b.l; return a.r<b.r; } int main() { scanf("%d",&n); for (int i=0;i<n;i++) { scanf("%d%d",&x,&w); a[i].l=x-w; a[i].r=x+w; } sort(a,a+n,cmp); int L=-INF,ans=0; for (int i=0;i<n;i++) if (a[i].l>=L) { L=a[i].r; ans++; } printf("%d",ans); }
标签:span struct sort ++ amp using int == bool
原文地址:http://www.cnblogs.com/xuanyiming/p/7570643.html