527D Clique Problem 判断一维线段没有两辆相交的最大线段数量
这题说的是给了n个位置 在x轴上 每个位置有一个权值为wi,然后将|xi - xj|>=wi+wj ,满足这个条件的点建一条边,计算着整张图中有多少多少个点构成的子图,使得这个子图的节点数尽量的大,这个式子进行转变 我们可以知道离i这个点为wi+xi xi-wi 范围内的点都是不可以的,那么我们就将这个n个点转化为了n条线段,那么现在的任务是计算这个n条线段两两不想交的 最大数量, 对于每条 线段有 左端点和右端点,我们将他们进行右端点排序, 然后进行每条边的判断前面k条线段的最右边那条是否与当先这条相交,如果相交,可以得知这条线段我们是不会使用的,因为我们有比他更加优的线段,在前面,如果不想交我们就把线段条数+1.记录当前最右的那条线段。
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
using namespace std;
pair<int,int> P[];
int main()
{
int n;
while(scanf("%d",&n)==){
for(int i=; i<n; i++){
int x,w;scanf("%d%d",&x,&w);
P[i] = {x+w,x-w};
}
sort(P,P+n);
int r = -;
int ans=;
for(int i=; i<n; i++){
if(P[i].second>=r){
r = P[i].first; ans++;
}
}
printf("%d\n",ans);
}
return ;
}
527D Clique Problem 判断一维线段没有两辆相交的最大线段数量的更多相关文章
- CodeForces - 527D Clique Problem (图,贪心)
Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...
- Codeforces 527D Clique Problem
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...
- 527D.Clique Problem
题解: 水题 两种做法: 1.我的 我们假设$xi>xj$ 那么拆开绝对值 $$xi-w[i]>x[j]+w[j]$$ 由于$w[i]>0$,所以$x[i]+w[i]>x[j] ...
- POJ 2826 An Easy Problem? 判断线段相交
POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...
- 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) B - Clique Problem
B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- 回溯法——最大团问题(Maximum Clique Problem, MCP)
概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent ...
随机推荐
- yii的安装
1.安装composer windows系统直接下载Composer-Setup.exe 运行安装. 2.安装Composer asset plugin composer安装完成后,在一个可通过web ...
- [分布式系统学习]阅读笔记 Distributed systems for fun and profit 抽象 之二
本文是阅读 http://book.mixu.net/distsys/abstractions.html 的笔记. 第二章的题目是"Up and down the level of abst ...
- linux下git命令
1.初始化: 方式一.git clone,将远程的Git版本库,克隆到本地一份. 方式二.git init和git remote 2.git pull:将其他版本库代码更新到本地.例如:git pul ...
- Docker镜像制作
使用docker原始源为centos制作一个nginx镜像 pull一个centos镜像 docker pull centos 运行进入容器 docker run -it centos 容器内安装wg ...
- POJ 1185 - 炮兵阵地 & HDU 4539 - 郑厂长系列故事——排兵布阵 - [状压DP]
印象中这道题好像我曾经肝过,但是没肝出来,现在肝出来了也挺开心的 题目链接:http://poj.org/problem?id=1185 Time Limit: 2000MS Memory Limit ...
- Oracle HA 之 Server Pool 实战
--创建server pool的两种方式: 图形界面:console和dbca 演示-略 命令行工具:srvctl和crsctl --srvctl和crsctl创建server ...
- 冒泡排序之python
冒泡排序(Bubble sort) 两两比较相邻记录的关键字,如果反序则交换,直到没有反序记录为止. 1.算法描述: 比较相邻的元素.如果第一个比第二个大,就交换它们两个: 对每一对相邻元素作同样的工 ...
- a loosely strongly typed language
JavaScript: The Definitive Guide, Sixth Edition by David Flanagan As explained above, the following ...
- disk_free_space
$df = disk_free_space('/')/1024/1024/1024; $df_c = disk_free_space("c:"); $df_d = disk_fre ...
- session hijacking-php.ini
wamp->php.ini ; This option forces PHP to fetch and use a cookie for storing and maintaining; the ...