D. Clique Problem

本文探讨了一种特殊条件下的最大团问题,在一维坐标系中,通过将点的坐标和权重转换为区间端点的形式,利用这些区间的相对位置来高效地找到满足特定连接条件的最大团。
D. Clique Problem
time limit per test
 2 seconds
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two of them are connected by an edge in graph G. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph.

Consider n distinct points on a line. Let the i-th point have the coordinate xi and weight wi. Let's form graph G, whose vertices are these points and edges connect exactly the pairs of points (i, j), such that the distance between them is not less than the sum of their weights, or more formally: |xi - xj| ≥ wi + wj.

Find the size of the maximum clique in such graph.

Input

The first line contains the integer n (1 ≤ n ≤ 200 000) — the number of points.

Each of the next n lines contains two numbers xiwi (0 ≤ xi ≤ 109, 1 ≤ wi ≤ 109) — the coordinate and the weight of a point. All xi are different.

Output

Print a single number — the number of vertexes in the maximum clique of the given graph.

Sample test(s)
input
4
2 3
3 1
6 1
0 2
output
3
Note

If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars!

The picture for the sample test.






题意:给在一维坐标上给一系列点,点有两个参数:坐标xi,权wi,当两点间满足|xi-xj|>=wi+wj 那么两点间可连一条无向边,求最大集,使点集中任意两点间有边相连

思路: 对|xi-xj|>=wi+wj 分析,当加入一个点到最大集中,这个点与任何点均满足这个关系,所以试图发现这个不等关系的传递性。

可构造这样的模型,把每个点的参数改成(Xi,Yi)=(xi-wi,xi+wi),当满足Xj>Yi 的时候说明i与j之间可以连边

所以如何当把j点加入的最大集的时候要满足Xj>Yi&&Xj>Yi'&&Xj>Yi''&&....( 即对最大集的其他所有点均有Xj>Yi的关系)

所以可以把点先按{Xi}排序,当Xj>Yi的时候,加入到最大集中,且关系可以传递到其他点,所以所有点均有边

复杂度线性

[cpp]  view plain  copy
 print ?
  1. //GNU C++   Accepted    93 ms   3616 KB  
  2. #include<cstdio>  
  3. #include<iostream>  
  4. #include<cstring>  
  5. #include<algorithm>  
  6. #include<vector>  
  7. using namespace std;  
  8. typedef pair<int,int >pii;  
  9. vector<pii> all;  
  10. int main()  
  11. {  
  12.     int n,ans=0;  
  13.     cin>>n;  
  14.     for(int i=1;i<=n;i++)  
  15.     {  
  16.         int x,w;  
  17.         scanf("%d%d",&x,&w);  
  18.         all.push_back(pii(x-w,x+w));  
  19.     }  
  20.     sort(all.begin(),all.end());  
  21.     int last=-0x3f3f3f3f;  
  22.     for(vector<pii>::iterator it = all.begin();it!=all.end();it++)  
  23.     {  
  24.         if(last<=(*it).first )  
  25.             last = (*it).second,ans++;  
  26.         else if(last>(*it).second)  
  27.             last=(*it).second;//贪心替换上一个点  
  28.     }  
  29.     cout<<ans<<endl;  
  30.     return 0;  
  31. }  
CLIQUE(Clustering In QUEst)是一种基于网格的聚类算法,主要用于处理高维数据集。它通过将每个维度划分为有限数量的区间,从而构建一个多维网格结构,并在这些网格单元中识别密集区域以形成聚类[^1]。 ### CLIQUE 的用途 - **发现数据中的自然分组**:CLIQUE 可以自动识别出数据集中存在的不同簇,这些簇代表了数据点之间的相似性模式。 - **处理高维数据**:相比于传统的聚类方法如 K-means 或层次聚类,CLIQUE 更适合于分析具有多个特征的数据集。 - **提供可解释性强的结果**:由于其基于网格的方法,CLIQUE 能够给出清晰的边界定义来区分不同的簇,这有助于对结果进行直观的理解和可视化。 ### 应用领域 - **市场细分**:企业可以利用 CLIQUE 来根据客户属性对消费者群体进行划分,以便实施更加精准有效的营销策略。 - **图像分割**:在计算机视觉任务中,CLIQUE 可用于从图像中提取有意义的对象或区域,这对于后续的目标识别等步骤至关重要。 - **生物信息学**:对于基因表达数据分析来说,使用 CLIQUE 可帮助科学家们找到潜在的功能相关基因群组,促进疾病机制的研究与新药开发。 - **文档分类**:当面对大量文本文件时,该算法能够协助组织和管理内容,按照主题或其他标准将文档归类到相应的类别之中。 - **网络入侵检测**:通过对正常行为模式的学习,CLIQUE 也能用来辨别异常活动,辅助网络安全防护系统及时响应威胁。 此外,随着技术的发展,CLIQUE 还可能被应用于更多新兴领域,比如物联网设备产生的复杂数据流分析、社交媒体上的用户行为研究等方面。 ```python # 注意: 下面提供的代码示例是针对另一种简单聚类算法K-means的实现, # 因为Python标准库中并没有直接支持CLIQUE算法的包。 from sklearn.cluster import KMeans import numpy as np # 创建一个随机二维数据集作为演示 X = np.random.rand(100, 2) # 初始化KMeans模型并拟合数据 kmeans = KMeans(n_clusters=3) kmeans.fit(X) # 输出聚类中心及标签 print("Cluster centers:", kmeans.cluster_centers_) print("Labels for each point:", kmeans.labels_) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值