【题目描述】
数轴上有 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

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long lol;
struct Node
{
lol l,r;
}a[];
lol c[],n,m,s[],num,sz,f[],ans;
bool cmp(Node a,Node b)
{
return a.r<b.r;
}
lol query(int rt,int l,int r,int L,int R)
{
if (l>=L&&r<=R)
{
return c[rt];
}
int mid=(l+r)/;
lol s=;
if (L<=mid) s=max(s,query(rt*,l,mid,L,R));
if (R>mid) s=max(s,query(rt*+,mid+,r,L,R));
c[rt]=max(c[rt*],c[rt*+]);
return s;
}
void update(int rt,int l,int r,int x,lol d)
{
if (l==r)
{
c[rt]=max(c[rt],d);
return;
}
int mid=(l+r)/;
if (x<=mid) update(rt*,l,mid,x,d);
else update(rt*+,mid+,r,x,d);
c[rt]=max(c[rt*],c[rt*+]);
}
int main()
{int i;
lol w,x;
cin>>n;
for (i=;i<=n;i++)
{
scanf("%lld%lld",&x,&w);
a[i].l=x-w;a[i].r=x+w;
s[++num]=x-w;s[++num]=x+w;
}
sort(a+,a+n+,cmp);
sort(s+,s+num+);
sz=unique(s+,s+num+)-(s+);
//cout<<sz<<endl;
for (i=;i<=n;i++)
{
a[i].l=lower_bound(s+,s+sz+,a[i].l)-s;
a[i].r=lower_bound(s+,s+sz+,a[i].r)-s;
}
for (i=;i<=n;i++)
{
f[i]=query(,,sz,,a[i].l)+;
ans=max(ans,f[i]);
update(,,sz,a[i].r,f[i]);
}
cout<<ans;
}

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. 1013团队Beta冲刺day4

    项目进展 李明皇 今天解决的进度 因服务器端未完成登录态维护,故无法进行前后端联动. 明天安排 前后端联动调试 林翔 今天解决的进度 因上课和实验室事务未完成登录态维护 明天安排 完成登录态维护 孙敏 ...

  2. 冲刺NO.8

    Alpha冲刺第八天 站立式会议 项目进展 项目稳步进行,项目的基础部分如基本信息管理,信用信息管理等部分已相对比较完善. 问题困难 技术困难在短期内很难发生质的变化,而本项目由于选择了队员不太熟悉的 ...

  3. python第三方库requests详解

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  4. 【iOS】字号问题

    一,ps和pt转换 px:相对长度单位.像素(Pixel).(PS字体) pt:绝对长度单位.点(Point).(iOS字体) 公式如下: pt=(px/96)*72. 二,字体间转换 1in = 2 ...

  5. Hibernate之HQL

    SQL语句的DML操作不外乎:增,删,改,查 增加 :  save(),persist() 删除 :   delete() 改动 :   update() 查询  :  get() ,load() 其 ...

  6. Java 后端微信小程序支付demo (网上说的坑里面基本上都有)

    Java 后端微信小程序支付 一.遇到的问题 1. 商户号该产品权限未开通,请前往商户平台>产品中心检查后重试 2.签名错误 3.已经调起微信统一下单接口,可以拿到预支付ID,但是前端支付的时候 ...

  7. 16-TypeScript装饰器模式

    在客户端脚本中,有一个类通常有一个方法需要执行一些操作,当我们需要扩展新功能,增加一些操作代码时,通常需要修改类中方法的代码,这种方式违背了开闭的原则. 装饰器模式可以动态的给类增加一些额外的职责.基 ...

  8. django启动uwsgi报错

    查看uwsgi.log *** Starting uWSGI 2.0.17 (64bit) on [Thu Apr 5 17:46:15 2018] *** compiled with version ...

  9. thinkphp框架的大D方法应用

    大D方法中需要传递一个模型,比如UserModer,就传递D('User'),而数据库中存在一个表比如think_user,其中think就是前缀. 在UserModel里面存在自动验证.自动完成可以 ...

  10. LeetCode & Q1-Two Sum-Easy

    Array Hash Table Question Given an array of integers, return indices of the two numbers such that th ...