http://codeforces.com/problemset/problem/527/D

题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集合中的点两两之间存在边

化开有

xi-xj>=wi+wj ==> wj+xj<=wi-xi

xj-xi>=wi+wj ==> wi+wx<=wj-xj

发现本质相同,我们按x+w排序,从最小的往大的贪心连边,因为如果有一条边,那么比它小的也全部可以连到边。

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
struct node{
int x,w;
}p[];
int n;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
bool cmp(node a,node b){
return a.w+a.x<b.x+b.w;
}
int main(){
n=read();
for (int i=;i<=n;i++)
p[i].x=read(),p[i].w=read();
std::sort(p+,p++n,cmp);
int ans=,t=p[].w+p[].x;
for (int i=;i<=n;i++){
if (t<=p[i].x-p[i].w){
ans++;
t=p[i].x+p[i].w;
}
}
printf("%d\n",ans);
return ;
}

Codeforces 527D Clique Problem的更多相关文章

  1. CodeForces - 527D Clique Problem (图,贪心)

    Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...

  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 528]B. Clique Problem

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

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

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

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

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

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

  9. codeforces 340C Tourist Problem

    link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...

随机推荐

  1. word 生成目录

    生成目录: (1)Ctrl+End,到达文档的最后一页: (2)"插入"菜单--引用--索引和目录(此时出现索引和目录对话框): (3)单击"目录"选项卡 a. ...

  2. Linux系统编程(35)—— socket编程之TCP服务器的并发处理

    我们知道,服务器通常是要同时服务多个客户端的,如果我们运行上一篇实现的server和client之后,再开一个终端运行client试试,新的client就不能能得到服务了.因为服务器之支持一个连接. ...

  3. Eclipse设置合适的字体

    一直使用Eclipse开发,最近感觉Comic Sans MS不错,但我的eclipse的默认字体里没有. 如果系统里有这个字体的话,那可以很简单的将这个字体添加到Eclipse中: Windows ...

  4. New Year Permutation(Floyd+并查集)

    Description User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to mak ...

  5. C++与lua交互

    项目开发的脚本层用的是Lua,引擎用的是C++.但是经理不给开放引擎层的代码.刚好最近项目空闲,安排了学习C++跟Lua的通信. 一.C++与Lua数据交互 数据交互主要是通过C API来实现 首先, ...

  6. css入门之css选择器

    CSS选择器 css的选择器最常用的是class选择器,定义方式如下. <!DOCTYPE html> <html lang="en"> <head& ...

  7. Ubuntu16.04下部署 nginx+uwsgi+django1.9.7(虚拟环境pyenv+virtualenv)

    由于用的新版本系统,和旧的稍有差别,在网上搜了很多相关资料,搞了三天终于搞好在Ubuntu16.04下的部署,接下来就详细写写步骤以及其中遇到的问题.前提是安装有虚拟环境pyenv+virtualen ...

  8. 【性能优化】优化笔记之一:图像RGB与YUV转换优化

    本文主要介绍如何优化您自己的CODE,实现软件的加速.我们一个图象模式识别的项目,需要将RGB格式的彩色图像先转换成黑白图像.图像转换的公式如下: Y = 0.299 * R + 0.587 * G ...

  9. C++中数组初始化

    #include<iostream>using std::cout;using std::endl;int arr1[5];int arr2[5] = {1,3,5};int main() ...

  10. Linux下一些基本操作

    一.忘记root密码 1. sudo passwd root 2. 输入新密码. 二.查看内核版本: 1.查看内核版本命令:1) cat /proc/version 2) uname -a 3)  u ...