数轴上有n 个点,第i 个点的坐标为xi,权值为wi。两个点i,j之间存在一条边当且仅当 abs(xi-xj)>=wi+wj。 你需要求出这张图的最大团的点数。

Solution

把每个点看作以 \((x_i,0)\) 为圆心,半径为 \(r_i\) 的圆

那么如果不相交就有边相连

干脆看作线段吧,所以就是求最大不相交线段数

这就是一个很基础的贪心,以右端点为第一关键字,左端点为第二关键字 sort

然后“能取就取”即可

#include <bits/stdc++.h>
using namespace std; #define int long long
const int N = 400005; int n,x[N],w[N]; struct interval {
int l,r;
bool operator < (const interval &b) const {
return r < b.r;
}
} I[N]; signed main() {
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++) cin>>x[i]>>w[i];
for(int i=1;i<=n;i++) {
I[i].l=x[i]-w[i];
I[i].r=x[i]+w[i];
}
sort(I+1,I+n+1);
int pos=-1e9,ans=0;
for(int i=1;i<=n;i++) {
if(I[i].l>=pos) {
++ans;
pos=I[i].r;
}
}
cout<<ans;
}

[CF527D] Clique Problem - 贪心的更多相关文章

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

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

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

  4. B. Clique Problem(贪心)

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

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

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

  6. [codeforces 528]B. Clique Problem

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

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

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

  8. 回溯法——最大团问题(Maximum Clique Problem, MCP)

    概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent ...

  9. codeforces 442B B. Andrey and Problem(贪心)

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

随机推荐

  1. 用 Python 分析今年考研形势

    还有5天,就到了考研初试的时间了. ! 尽管今年研招网内部,已经做了优化改善,还是抵挡不住考生们的报名热情(网站崩溃). ​ 2017年考研人数增长至201万人, 2018年则达到238万人, 201 ...

  2. C#设计模式学习笔记:(11)享元模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7792973.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲结构型设计模式的第六个模式--享 ...

  3. mysql必知必会--使用数据处理函数

    函数 与其他大多数计算机语言一样,SQL支持利用函数来处理数据.函数 一般是在数据上执行的,它给数据的转换和处理提供了方便. 在前一章中用来去掉串尾空格的 RTrim() 就是一个函数的例子 函数没有 ...

  4. PRML学习准备

    因为很怕PRML课程,所以想提前学习下做点准备. 看的一个学习内容就是python数据处理那本书,比较仔细地学习了 numpy,大致看了pandas和 matplotlib ,有以下几点感受 nump ...

  5. Android中创建一个BroadcastReceiver

    首先创建一个java类继承BroadcastReceiver类 package com.example.service; import android.content.BroadcastReceive ...

  6. mysql 行级锁问题

    线上碰到存储过程死锁问题了,开始以为非主键查询 for update 会导致表锁,后来经过测试 innodb下for update索引生效的情况下 根据索引字段查询是行级锁,会将整个结果集进行上锁,直 ...

  7. excel的count、countif、sunif、if

    一.count统计数值个数 格式:count(指定区域)  , 例如:count(B2:G5) 二.countif统计数值满足条件个数 格式:COUNTIF(条件区域,指定条件)  ,例如:count ...

  8. 安装MYSQL到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:MYSQL-5.7 硬件要求:无 安装过程 1.基础配置 [root@localhost ~]# ...

  9. 项目启动时报错:java.io.EOFException

    解决方案 删除Tomcat里面的work\Catalina\localhost下的项目文件内容即可解决 问题原因 原因是由于项目测试中class文件或者其它文件更新过频繁

  10. Json与Ajax(注册实例)

    需要在服务器上进行哈 jquery的ajax方法: // jquery请求 $.ajax({ url: "./server/slider.json", type: "po ...