Codeforces 527D clique problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.