Description

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 ( ≤ n ≤  ) — the number of points.

Each of the next n lines contains two numbers xi, wi ( ≤ xi ≤ ,  ≤ wi ≤ ) — 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 Input

Input

Output

    假设点Xi>Xj,那么绝对值符号可以去掉,即Xi-Xj≥Wi+Wj。移项可以得到Xi-Wi≥Xj+Wj。这样的话,其实就确定了一个有向图的关系,题目转化为找结点数最多的有向图。运用贪心的思想,肯定希望第一个结点的坐标尽量小,以便于容纳更多的结点。因此事先计算出P(X+W,X-W)后放入vector,排序后从第一个点开始尝试,只要满足这样的关系式就努力往后拓展。这样得到的有向图结点数一定是最多的。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 200006
#define inf 1e12
int n;
struct Node{
int x,w;
}node[N];
struct Node1{
int num1,num2;
};
vector<Node1 > G; bool cmp(Node1 a,Node1 b){
if(a.num1!=b.num1) return a.num1<b.num1;
return a.num2<b.num2;
} int main()
{
while(scanf("%d",&n)==){
for(int i=;i<n;i++){
scanf("%d%d",&node[i].x,&node[i].w);
}
G.clear();
for(int i=;i<n;i++){
int num1=node[i].x+node[i].w;
int num2=node[i].x-node[i].w;
Node1 tmp;
tmp.num1=num1;
tmp.num2=num2;
G.push_back(tmp);
}
sort(G.begin(),G.end(),cmp);
int ans=;
Node1 tmp=G[];
for(int i=;i<G.size();i++){
if(tmp.num1<=G[i].num2){
ans++;
tmp=G[i];
}
} printf("%d\n",ans);
}
return ;
}

CodeForces - 527D Clique Problem (图,贪心)的更多相关文章

  1. Codeforces 527D Clique Problem

    http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...

  2. 527D.Clique Problem

    题解: 水题 两种做法: 1.我的 我们假设$xi>xj$ 那么拆开绝对值 $$xi-w[i]>x[j]+w[j]$$ 由于$w[i]>0$,所以$x[i]+w[i]>x[j] ...

  3. 527D Clique Problem 判断一维线段没有两辆相交的最大线段数量

    这题说的是给了n个位置 在x轴上 每个位置有一个权值为wi,然后将|xi - xj|>=wi+wj ,满足这个条件的点建一条边,计算着整张图中有多少多少个点构成的子图,使得这个子图的节点数尽量的 ...

  4. Codeforces Round #296 (Div. 1) B. Clique Problem 贪心

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

  5. Codeforces Round #296 (Div. 2) D. Clique Problem [ 贪心 ]

    传送门 D. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. [codeforces 528]B. Clique Problem

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

  7. 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 ...

  8. Codeforces Round #296 (Div. 1) B - Clique Problem

    B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...

  9. B. Clique Problem(贪心)

    题目链接: B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Eight(South Central USA 1998)(八数码) 分类: bfs 2015-07-05 22:34 1人阅读 评论(0) 收藏

    The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've see ...

  2. ubuntu 包维护

    gnats == bug; tox = tales xillia ubuntu回显当前目录

  3. SVN强制填写日志

    在F:\Repositories\版本库名\hooks下新建pre-commit.bat 内容如下: @echo off setlocal set SVN_BINDIR="C:\Progra ...

  4. 卡特兰数 Catalan数 ( ACM 数论 组合 )

    卡特兰数 Catalan数 ( ACM 数论 组合 ) Posted on 2010-08-07 21:51 MiYu 阅读(13170) 评论(1)  编辑 收藏 引用 所属分类: ACM ( 数论 ...

  5. UE是什么意思?用户体验设计师与UE设计是什么关系?

    本文来自:http://blog.sina.com.cn/s/blog_a6bebb3f01015h47.html 什么是UE(UE——UE就是用户体验度) 你会发觉他的使用很人性化:功能强大但操作简 ...

  6. [Java Web]Struts2解决中文乱码问题

    1.设置struts的字符编码,能够在struts.xml中添加下面代码: <constant name="struts.i18n.encoding" value=" ...

  7. java学习笔记day04

    1.static关键字  特点:1)随着类的加载而加载        2)优先于对象存在        3)被所有对象所共享        4)可以直接被类名调用(类名.静态成员) 注意:静态方法只能 ...

  8. 理解java中【同步】和【死锁】

    一.理解同步 要想解决资源共享的同步操作问题,可以使用两种方法: 使用同步代码块 之前学习过程中,代码块分为四种: l         普通代码块:是直接定义在方法之中的: l         构造块 ...

  9. oracle主机修改IP后客户端无法连接

    无论SQLPLUS还是PLSQL Developer连接均报错: ERROR:ORA-12154: TNS: 无法解析指定的连接标识符 解决方法:修改主机IP后,客户端修改tnsnames文件IP:还 ...

  10. hive大数据倾斜总结

    在做Shuffle阶段的优化过程中,遇到了数据倾斜的问题,造成了对一些情况下优化效果不明显.主要是因为在Job完成后的所得到的 Counters是整个Job的总和,优化是基于这些Counters得出的 ...