Test instructions: Give you a xi,wi point collection and ask you which of the largest subset satisfies |xi-xj| >= WI + WJ size is how much.
Problem solving Ideas: dp+ discretization + tree-like array. Think of it as an edge [Xi-wi,xi+wi] to cover the area.
Problem Solving Code:
1 //File name:d.cpp2 //Author:darkdream3 //Created time:2015 March 18 Wednesday 15:28 50 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - - using namespacestd; - #defineMAXN 700000 - intLowbit (intx) in { - returnX & (-x); to } + intTREE[MAXN]; - intGetsum (intx) the { * intsum =0; $ while(x >=1)Panax Notoginseng { -sum =Max (tree[x],sum); theX-=lowbit (x); + } A returnsum; the } + intN,m,tt; - voidUpdateintKintv) $ { $ while(k <=TT) - { -TREE[K] =Max (tree[k],v); theK + =Lowbit (k); - }Wuyi } the structnode{ - intx, L, R; Wu }QU[MAXN]; - intcmpintXinty) About { $ returnX <y; - } - intnodecmp (node x, node Y) - { A returnx.x <y.x; + } themap<int,int>MP; - intCH[MAXN]; $ intMain () { them =0 ; thescanf"%d",&n); the intTM; the for(inti =1; I <= N;i + +) - { inscanf"%d%d",&qu[i].x,&TM); theQU[I].L = qu[i].x-TM; theQU[I].R = qu[i].x +TM; Aboutch[m+1] =QU[I].L; thech[m+2] =QU[I].R; theM + =2; the } +Sort (qu+1, qu+1+n,nodecmp); -Sort (ch+1, ch+1+m,cmp); thech[0] = -1e9- +;Bayitt =0 ; the for(inti =1; I <= M;i + +) the { - if(Ch[i]! = ch[i-1]) - { thett + + ; theMp[ch[i]] =tt; the } the } - intAns =0 ; the for(inti =1; I <= N;i + +) the { the intL =MP[QU[I].L];94Ans =getsum (l); the //printf ("%d%d%i64d\n", L,mp[qu[i].r],getsum (L)); theUpdate (Mp[qu[i].r],ans +1); the }98Ans =getsum (TT); Aboutprintf"%d\n", ans); - return 0;101}
View Code
Codeforces 527D clique problem