Codeforces Round #296 (Div. 1) B. Clique Problem 贪心
2 seconds
256 megabytes
standard input
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.
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.
Print a single number — the number of vertexes in the maximum clique of the given graph.
4
2 3
3 1
6 1
0 2
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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
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-9
const 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<bb.y;
return aa.x<bb.x;
}
int main()
{
int n,aa,bb;
cin>>n;
for(int i=;i<n;i++)
{
scanf("%d%d",&aa,&bb);
a[i].x=aa+bb;
a[i].y=aa-bb;
}
sort(a,a+n,cmp);
int l=-inf;
int ans=;
for(int i=;i<n;i++)
{
if(a[i].y>=l)
{
l=a[i].x;
ans++;
}
}
cout<<ans<<endl;
}
Codeforces Round #296 (Div. 1) B. Clique Problem 贪心的更多相关文章
- 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 ...
- Codeforces Round #296 (Div. 1) B - Clique Problem
B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...
- 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 ...
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #296 (Div. 1) E. Triangles 3000
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...
- Codeforces Round #361 (Div. 2) C.NP-Hard Problem
题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. ...
随机推荐
- 非极大值抑制(NMS,Non-Maximum Suppression)的原理与代码详解
1.NMS的原理 NMS(Non-Maximum Suppression)算法本质是搜索局部极大值,抑制非极大值元素.NMS就是需要根据score矩阵和region的坐标信息,从中找到置信度比较高的b ...
- haproxy支持的负载均衡算法详解
目前haproxy支持的负载均衡算法有如下8种: 1.roundrobin 表示简单的轮询,每个服务器根据权重轮流使用,在服务器的处理时间平均分配的情况下这是最流畅和公平的算法.该算法是动态的,对于实 ...
- mysql高可用架构 -> MHA主从复制-03
GTID复制技术说明 GTID的全称为 global transaction identifier ,可以翻译为全局事务标示符,GTID在原始master上的事务提交时被创建.GTID需要在全局的主- ...
- Android 抽屉导航
原文地址 http://developer.android.com/training/implementing-navigation/nav-drawer.html 创建抽屉导航 导航抽屉是在 屏幕左 ...
- ubuntu 16.04 网卡配置 虚拟机上网
看所有网卡(包括未启动的) ifconfig -a 或者 ip link 查看当前网卡配置,打开配置文件/etc/network/interfaces 设置静态IP(dhcp 为动态获取,static ...
- 使用Netty4实现基本的消息分发
示例工程代码 可从附件下载 具体的说明和用法在后面介绍 需求与目的 一个游戏服务端需要处理各种业务逻辑,每一种业务逻辑都对应着一个请求消息和一个响应消息.那么服务端需要把这些不同的消息自动分发到对应的 ...
- ASP.NET中Literal,只增加纯粹的内容,不附加产生html代码
页面代码 <div style="float: right; color: #666; line-height: 30px; margin-right: 12px;" id= ...
- Git简明教程二、开始进行版本管理
上一篇介绍了Git中的一些基本概念.本篇来实际看一看如何通过几个常用命令来快速上手Git,完成版本管理的日常操作(核心操作). 0. 准备工作 安装Git后,请先在你的电脑上新建或选择一个目录作为测试 ...
- django-suit的使用
1.django-suit 是Django admin美化插件 django-suit官方文档 2.django-suit安装 #python pip install django-suit #pyt ...
- .gitignore文件如何编写?
.gitignore文件即 项目中不需要被追踪(track)且上传到git系统的文件 <1>忽略文件的原则 a.忽略操作系统自动生成的文件,比如缩略图等 b.忽略编译生成的中间文件.可执行 ...