clique
【题目描述】
数轴上有 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的更多相关文章
- UVA11324 The Largest Clique[强连通分量 缩点 DP]
UVA - 11324 The Largest Clique 题意:求一个节点数最大的节点集,使任意两个节点至少从一个可以到另一个 同一个SCC要选一定全选 求SCC 缩点建一个新图得到一个DAG,直 ...
- 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 ...
- CLIQUE 聚类算法以及Java实现+多线程
CLIQUE(Clustering In QUEst)是一种简单的基于网格的聚类方法,用于发现子空间中基于密度的簇.CLIQUE把每个维划分成不重叠的区间,从而把数据对象的整个嵌入空间划分成单元.它使 ...
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- 周赛-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 ...
- CodeForces - 527D Clique Problem (图,贪心)
Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...
- 【最大团】【HDU1530】【Maximum Clique】
先上最大团定义: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题,在国际上已有广泛的研究,而国内对MCP问题的研究则还处于起步 ...
- hdu 1530 Maximum Clique
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1530 题目分类:最大团问题 DP + DFS 代码: #include<bits/stdc++. ...
- UVA 11324 - The Largest Clique(强连通分量+缩点)
UVA 11324 - The Largest Clique 题目链接 题意:给定一个有向图,要求找一个集合,使得集合内随意两点(u, v)要么u能到v,要么v能到u,问最大能选几个点 思路:强连通分 ...
- uva 11324 The Largest Clique(图论-tarjan,动态规划)
Problem B: The Largest Clique Given a directed graph G, consider the following transformation. First ...
随机推荐
- 第七周PTA作业
第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...
- 团队作业7——Beta版本冲刺计划及安排
上一个阶段的总结: 在Alpha阶段,我们小组已近完成了大部分的功能要求,小组的每一个成员都发挥了自己的用处.经过了这么久的磨合,小组的成员之间越来越默契,相信在接下来的合作中,我们的开发速度会越来越 ...
- jav音频格式转换 ffmpeg 微信录音amr转mp3
项目背景: 之前公司开发了一个微信公众号,要求把js-sdk录音文件在web网页也能播放.众所周知,html的<audio>标签ogg,mp3,wav,也有所说苹果safari支持m4a格 ...
- [Android FrameWork 6.0源码学习] View的重绘过程之WindowManager的addView方法
博客首页:http://www.cnblogs.com/kezhuang/p/关于Activity的contentView的构建过程,我在我的博客中已经分析过了,不了解的可以去看一下<[Andr ...
- 06-移动端开发教程-fullpage框架
CSS3的新特性已经讲完了,接下来我们看一下jQuery的一个全屏jQuery全屏滚动插件fullPage.js.我们经常见到一些全屏的特绚丽页面,手指或者鼠标滑动一下就是一整屏切换,而且还有各种效果 ...
- 改变input的placeholder颜色
input::-webkit-input-placeholder{ color:#666; } input::-ms-input-placeholder{ color:#666; } input::- ...
- 构建微服务开发环境7————使用Github管理项目代码的版本
[内容指引] 1.注册GitHub帐号: 2.下载Github Desktop客户端: 3.macOS安装Github Desktop客户端: 4.windows安装Github Desktop客户端 ...
- JAVA_SE基础——48.多态
面向对象程序设计的三个特点是封装.继承和多态.前面已经学习了前两个特点.本章节将介绍多态性. 多态:一个对象具备多种形态.(父类的引用类型变量指向了子类的对象)或者是接口 的引用类型变量指向了接口实现 ...
- KNN算法的代码实现
# -*- coding: utf-8 -*-"""Created on Wed Mar 7 09:17:17 2018 @author: admin"&quo ...
- 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 ...