【题目描述】
数轴上有 n 个点,第 i 个点的坐标为 xi,权值为 wi。两个点 i,j 之
间存在一条边当且仅当 abs(xi-xj)>=wi+wj。
你需要求出这张图的最大团的点数。
(团就是两两之间有边的顶点
集合)
【输入数据】
第一行一个整数 n,接下来 n 行每行两个整数 xi,wi。
【输出数据】
一行一个整数表示答案。
【样例输入】
4
2 3
3 1
6 1
0 2
【样例输出】
3
【数据范围】
对于 20%的数据,n<=10。
对于 60%的数据,n<=1000。
对于 100%的数据,n<=200000,0<=|xi|,wi<=10^9。

先按x排序,则连边条件变为:

xi-xj>=wi+wj

xi-wi>=xj+wj

于是建边的条件可以理解为:有两个区间[xi-wi,xi+wi],[xj-wj,xj+wj],如果区间不相交那么连边

于是完全图就相当于求最长的不相交区间集

这里用的是dp+线段树+离散

把每一个xi+wi,xi-wi离散

然后每一次查询线段树上位于区间左边的最大f值

然后在线段树上更新当前右端点为当前f

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. typedef long long lol;
  7. struct Node
  8. {
  9. lol l,r;
  10. }a[];
  11. lol c[],n,m,s[],num,sz,f[],ans;
  12. bool cmp(Node a,Node b)
  13. {
  14. return a.r<b.r;
  15. }
  16. lol query(int rt,int l,int r,int L,int R)
  17. {
  18. if (l>=L&&r<=R)
  19. {
  20. return c[rt];
  21. }
  22. int mid=(l+r)/;
  23. lol s=;
  24. if (L<=mid) s=max(s,query(rt*,l,mid,L,R));
  25. if (R>mid) s=max(s,query(rt*+,mid+,r,L,R));
  26. c[rt]=max(c[rt*],c[rt*+]);
  27. return s;
  28. }
  29. void update(int rt,int l,int r,int x,lol d)
  30. {
  31. if (l==r)
  32. {
  33. c[rt]=max(c[rt],d);
  34. return;
  35. }
  36. int mid=(l+r)/;
  37. if (x<=mid) update(rt*,l,mid,x,d);
  38. else update(rt*+,mid+,r,x,d);
  39. c[rt]=max(c[rt*],c[rt*+]);
  40. }
  41. int main()
  42. {int i;
  43. lol w,x;
  44. cin>>n;
  45. for (i=;i<=n;i++)
  46. {
  47. scanf("%lld%lld",&x,&w);
  48. a[i].l=x-w;a[i].r=x+w;
  49. s[++num]=x-w;s[++num]=x+w;
  50. }
  51. sort(a+,a+n+,cmp);
  52. sort(s+,s+num+);
  53. sz=unique(s+,s+num+)-(s+);
  54. //cout<<sz<<endl;
  55. for (i=;i<=n;i++)
  56. {
  57. a[i].l=lower_bound(s+,s+sz+,a[i].l)-s;
  58. a[i].r=lower_bound(s+,s+sz+,a[i].r)-s;
  59. }
  60. for (i=;i<=n;i++)
  61. {
  62. f[i]=query(,,sz,,a[i].l)+;
  63. ans=max(ans,f[i]);
  64. update(,,sz,a[i].r,f[i]);
  65. }
  66. cout<<ans;
  67. }

clique的更多相关文章

  1. UVA11324 The Largest Clique[强连通分量 缩点 DP]

    UVA - 11324 The Largest Clique 题意:求一个节点数最大的节点集,使任意两个节点至少从一个可以到另一个 同一个SCC要选一定全选 求SCC 缩点建一个新图得到一个DAG,直 ...

  2. CF #296 (Div. 1) B. Clique Problem 贪心(构造)

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. CLIQUE 聚类算法以及Java实现+多线程

    CLIQUE(Clustering In QUEst)是一种简单的基于网格的聚类方法,用于发现子空间中基于密度的簇.CLIQUE把每个维划分成不重叠的区间,从而把数据对象的整个嵌入空间划分成单元.它使 ...

  4. [codeforces 528]B. Clique Problem

    [codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...

  5. 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏

    Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...

  6. CodeForces - 527D Clique Problem (图,贪心)

    Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...

  7. 【最大团】【HDU1530】【Maximum Clique】

    先上最大团定义: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题,在国际上已有广泛的研究,而国内对MCP问题的研究则还处于起步 ...

  8. hdu 1530 Maximum Clique

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1530 题目分类:最大团问题 DP + DFS 代码: #include<bits/stdc++. ...

  9. UVA 11324 - The Largest Clique(强连通分量+缩点)

    UVA 11324 - The Largest Clique 题目链接 题意:给定一个有向图,要求找一个集合,使得集合内随意两点(u, v)要么u能到v,要么v能到u,问最大能选几个点 思路:强连通分 ...

  10. uva 11324 The Largest Clique(图论-tarjan,动态规划)

    Problem B: The Largest Clique Given a directed graph G, consider the following transformation. First ...

随机推荐

  1. 第七周PTA作业

    第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...

  2. 团队作业7——Beta版本冲刺计划及安排

    上一个阶段的总结: 在Alpha阶段,我们小组已近完成了大部分的功能要求,小组的每一个成员都发挥了自己的用处.经过了这么久的磨合,小组的成员之间越来越默契,相信在接下来的合作中,我们的开发速度会越来越 ...

  3. jav音频格式转换 ffmpeg 微信录音amr转mp3

    项目背景: 之前公司开发了一个微信公众号,要求把js-sdk录音文件在web网页也能播放.众所周知,html的<audio>标签ogg,mp3,wav,也有所说苹果safari支持m4a格 ...

  4. [Android FrameWork 6.0源码学习] View的重绘过程之WindowManager的addView方法

    博客首页:http://www.cnblogs.com/kezhuang/p/关于Activity的contentView的构建过程,我在我的博客中已经分析过了,不了解的可以去看一下<[Andr ...

  5. 06-移动端开发教程-fullpage框架

    CSS3的新特性已经讲完了,接下来我们看一下jQuery的一个全屏jQuery全屏滚动插件fullPage.js.我们经常见到一些全屏的特绚丽页面,手指或者鼠标滑动一下就是一整屏切换,而且还有各种效果 ...

  6. 改变input的placeholder颜色

    input::-webkit-input-placeholder{ color:#666; } input::-ms-input-placeholder{ color:#666; } input::- ...

  7. 构建微服务开发环境7————使用Github管理项目代码的版本

    [内容指引] 1.注册GitHub帐号: 2.下载Github Desktop客户端: 3.macOS安装Github Desktop客户端: 4.windows安装Github Desktop客户端 ...

  8. JAVA_SE基础——48.多态

    面向对象程序设计的三个特点是封装.继承和多态.前面已经学习了前两个特点.本章节将介绍多态性. 多态:一个对象具备多种形态.(父类的引用类型变量指向了子类的对象)或者是接口 的引用类型变量指向了接口实现 ...

  9. KNN算法的代码实现

    # -*- coding: utf-8 -*-"""Created on Wed Mar 7 09:17:17 2018 @author: admin"&quo ...

  10. LeetCode & Q121-Best Time to Buy and Sell Stock-Easy

    Array DP Description: Say you have an array for which the ith element is the price of a given stock ...