标签:str ret href 线段 重叠 names ble cst scanf
这题还挺水的,把那个式子稍微变形一下就可以的到xi-wi>=xj+wj,易知:若把每个点看做一条线段,左端点是xi-wi,右端点是xi+wi,就只要求最多的不重叠的线段数就可以了,然后就是乱搞了
#include <cstdio> #include <algorithm> using namespace std; const int N=200005; int n; struct point{int x,w;}a[N]; inline bool cmp(point a,point b){return a.x<b.x;} struct node{int l,r;}line[N]; inline bool cmp1(node a,node b){return (a.r!=b.r)?(a.r<b.r):(a.l<b.l);} int main() { int i,re=0,tmp=-2e9; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].w); sort(a+1,a+n+1,cmp); for(i=1;i<=n;i++)line[i].l=a[i].x-a[i].w,line[i].r=a[i].x+a[i].w; sort(line+1,line+n+1,cmp1); for(i=1;i<=n;i++) { if(tmp<=line[i].l){tmp=line[i].r; re++;} }printf("%d\n",re); }
标签:str ret href 线段 重叠 names ble cst scanf
原文地址:https://www.cnblogs.com/gaojunonly1/p/9736518.html