博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #296 (Div. 1) B. Clique Problem 贪心
阅读量:6156 次
发布时间:2019-06-21

本文共 2602 字,大约阅读时间需要 8 分钟。

B. 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 xi, wi (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 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.
思路 排序,然后贪心,然后乱搞,类似于区间覆盖问题…… 代码
//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 200001#define mod 10007#define eps 1e-9const int inf=0x7fffffff; //无限大/*inline ll read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}*///**************************************************************************************struct node{ int x,y;};node a[maxn];bool cmp(node aa,node bb){ if(aa.x==bb.x) return aa.y
>n; for(int i=0;i
=l) { l=a[i].x; ans++; } } cout<
<

 

转载地址:http://xiifa.baihongyu.com/

你可能感兴趣的文章
浅入浅出Typescript Decorators
查看>>
MongoDB 命令速查表
查看>>
IDC 2018可穿戴市场报告:耳戴式设备占比四分之一,成“新宠”
查看>>
计算二叉树叶子节点的数目
查看>>
Tensorflow源码解析6 -- TensorFlow本地运行时
查看>>
Django 表单
查看>>
扬尘监测系统_工地扬尘监测_工地扬尘监测解决方案
查看>>
Oracle11gR2在9x8hk..Windows18669144449 命名进入Oracle
查看>>
Chrome 被曝 0day 漏洞,可让黑客获取用户数据
查看>>
Django 模板
查看>>
gitbook
查看>>
约三分之二的 DDoS 攻击指向通信服务提供商
查看>>
怎样把开启的服务放到后台?
查看>>
LAMP-fpm
查看>>
gradle研究
查看>>
网络设备配置
查看>>
MySQL 索引条件下推 Index Condition Pushdown
查看>>
在Powershell中禁止执行脚本
查看>>
Netscreen防火墙常用命令-管理篇
查看>>
利用Linux系统生成随机密码的10种方法
查看>>