数轴上有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. ASP.NET Core MVC的基础学习笔记

    最近由于“武汉肺炎”疫情在家办公,也没闲着,最近学习了一下asp.net core mvc的一些网页开发的的基础知识,话不多说直接上教程! 一.创建Web应用程序 1)创建新项目--->找到 “ ...

  2. Uncaught TypeError: Cannot set property 'onclick' of null解决办法

    如果把js内容直接放在这个head标签以内,button按钮不能正常点击更换body的背景颜色,报错提示:demo6.html:16 Uncaught TypeError: Cannot set pr ...

  3. CentOS7安装MySQL报错,解决Failed to start mysqld.service: Unit not found

    当输入命令 ~]# systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 Failed to start mysqld.service: Unit not ...

  4. 三星正在改善1Gb MRAM寿命问题

    据报道三星已经成功研发出有望替代嵌入式闪存存储器(eFlash)的嵌入式磁阻随机访问内存(eMRAM),容量为1Gb,测试芯片的优良率已达90%. 随着5G物联网时代的来临,存储器领域发展快速,而在这 ...

  5. Windows10设置系统参数

     屏幕分辨率设置 电源屏幕显示时间 投影可以进行手机投影到电脑进行操作,远程桌面可以进行远程访问,如云服务器 设置桌面图标和背景 设置默认应用 安装软件,必备的几项软件 --其中个人认为(1)(2)是 ...

  6. node模块化开发基本知识学习笔记

    传统非模块化开发缺点: 1.命名冲突 2.文件依赖 标准的模块化规范: 1.AMD-requirejs 2.CMD-seajs 服务器端模块化规范: 1.CommonJS-Node.js 模块化相关的 ...

  7. centos 源码编译mysql5.7

    1- 源码安装mysql5.7 [自动安装脚本:https://files-cdn.cnblogs.com/files/lemanlai/make_mysql.sh] groupadd mysql u ...

  8. Mac IDEA 2019.3.1下载及破解,可激活至2089年

    背景 目前IDEA已更新到2019.3.3,但是下载这个版本后使用目前网上的常见破解方法会出现各种问题.比如使用注册码方式提示license key is in legacy format,或者使用L ...

  9. 3.3 Zabbix容器安装

    课程资料:https://github.com/findsec-cn/zabbix 1. yum install docker-latest    :安装最新的docker   ,选择 y  ,等待自 ...

  10. Wannafly Winter Camp 2020 Day 6G 单调栈 - 贪心

    对于排列 \(p\),它的单调栈 \(f\) 定义为,\(f_i\) 是以 \(p_i\) 结尾的最长上升子序列的长度 先给定 \(f\) 中一些位置的值,求字典序最小的 \(p\) 使得它满足这些值 ...