题解:

水题

两种做法:

1.我的

我们假设$xi>xj$ 那么拆开绝对值

$$xi-w[i]>x[j]+w[j]$$

由于$w[i]>0$,所以$x[i]+w[i]>x[j]+w[j]$

然后我们只需要在线段树上查询一段的最大值然后再单点取max就行了

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (itn i=t;i>=h;i--)
#define me(x) memset(x,0,sizeof(x))
#define ll long long
#define mid (h+((t-h)>>1))
namespace IO
{
char ss[<<],*A=ss,*B=ss;
IL char gc()
{
return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;
}
template<class T>void read(T &x)
{
rint f=,c; while (c=gc(),c<||c>) if (c=='-') f=-; x=(c^);
while (c=gc(),c>&&c<) x=(x<<)+(x<<)+(c^); x*=f;
}
char sr[<<],z[]; int Z,C=-;
template<class T>void wer(T x)
{
if (x<) sr[++C]='-',x=-x;
while (z[++Z]=x%+,x/=);
while (sr[++C]=z[Z],--Z);
}
IL void wer1()
{
sr[++C]=' ';
}
IL void wer2()
{
sr[++C]='\n';
}
template<class T>IL void maxa(T &x,T y) { if (x<y) x=y; }
template<class T>IL void mina(T &x,T y) { if (x>y) x=y; }
template<class T>IL T MAX(T x,T y) {return x>y?x:y;}
template<class T>IL T MIN(T x,T y) {return x<y?x:y;}
};
using namespace IO;
const int N=3e5;
const int N1=8e6;
const int M=2e9;
struct re{
int x,w;
}a[N];
int rt,n;
bool cmp(re x,re y)
{
return x.x<y.x;
}
struct sgt{
int cnt,ls[N1],rs[N1],v[N1];
void change(int &x,int h,int t,int pos,int k)
{
if (!x) x=++cnt;
maxa(v[x],k);
if (h==t) return;
if (pos<=mid) change(ls[x],h,mid,pos,k);
else change(rs[x],mid+,t,pos,k);
}
int query(int x,int h,int t,int h1,int t1)
{
if (h1<=h&&t<=t1) return v[x];
int ans=;
if (h1<=mid) maxa(ans,query(ls[x],h,mid,h1,t1));
if (mid<t1) maxa(ans,query(rs[x],mid+,t,h1,t1));
return ans;
}
}S;
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
read(n);
rep(i,,n)
{
read(a[i].x); read(a[i].w);
}
sort(a+,a+n+,cmp);
rep(i,,n)
{
int k=a[i].x-a[i].w;
int ans=;
if (k>) ans=S.query(rt,,M,,k);
S.change(rt,,M,a[i].w+a[i].x,ans+);
}
cout<<S.v[]<<endl;
return ;
}

2.题解的做法

像这种题目比较容易想到用贪心去解决

我们把绝对值等价一下

$$w[j]+x[j]<=x[i]-w[i] \ \ \ \ w[i]+x[i]<=x[j]-w[j] $$两个满足一个即可

而我们发现对任意两个用这个不等式等价于所有$[x[i]-w[i],x[i]+w[i]]$区间都不想相交

这样我们只需要按照右端点排序贪心取就可以了

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. Codeforces 527D Clique Problem

    http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...

  3. 527D Clique Problem 判断一维线段没有两辆相交的最大线段数量

    这题说的是给了n个位置 在x轴上 每个位置有一个权值为wi,然后将|xi - xj|>=wi+wj ,满足这个条件的点建一条边,计算着整张图中有多少多少个点构成的子图,使得这个子图的节点数尽量的 ...

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

  5. [codeforces 528]B. Clique Problem

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

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

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

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

  8. B. Clique Problem(贪心)

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

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

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

随机推荐

  1. CentOS下安装nvm

    1安装版本管理工具git yum install git 查看git版本 git --version 2 安装Node.js版本管理工具nvm curl -o- https://raw.githubu ...

  2. Virtual Box虚拟机安装Ubuntu16.04以及整理的一些基本操作

    事先声明,参考自:https://www.cnblogs.com/wyt007/p/9856290.html 撰写此文,纯属是为了便利以后换电脑重装. 转载请注明地址:https://www.cnbl ...

  3. [SCOI2006] 数字立方体

    题目类型:三维前缀和+同余方程 传送门:>Here< 题意:给出一个立方体,求有多少个子立方体的和为\(k\)的倍数 解题思路 暴力做法:\(O(n^6)\)枚举子立方体 考虑只枚举长和宽 ...

  4. LoadRunner【第二篇】原理及使用流程

    loadrunner工作原理 性能测试只关注底层数据,不关注业务,不关注客户端动作.所以,脚本运行正确不一定业务就正确(业务是否正确,如果是查询,我们可以通过检查点来判断:如果是增删改操作,可以看通过 ...

  5. nginx日志相关的查询

    IP相关统计 统计IP访问量(独立ip访问数量) awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时间段的IP访问量(4-5点) gr ...

  6. 百度在职 iOS 架构师的成长笔记,送给还在迷茫的你!

    前言 我们经常在网上会看到这样的文章,你的同龄人正在如何如何.......这是典型的贩卖焦虑的文章.的确,现阶段,刚毕业几年的年轻人,面临车,房子等,有时候压力挺大的. 但你过度焦虑的话,每天生活在恐 ...

  7. Luogu_2015 二叉苹果树

    题目链接 SB 裸题……就是想随便挂在这里……同样的题还有 Luogu_2014 选课. Luogu_2015 二叉苹果树 #include <queue> #include <cs ...

  8. Python中如何设置输出文字的颜色

    一.语法 1.实现过程 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关.控制字符颜色的转义序列是以ESC开头,即用\033来完成   2.书写过程 开头部分: \033 ...

  9. R语言统计学习-1简介

    一. 统计学习概述 统计学习是指一组用于理解数据和建模的工具集.这些工具可分为有监督或无监督.1.监督学习:用于根据一个或多个输入预测或估计输出.常用于商业.医学.天体物理学和公共政策等领域.2.无监 ...

  10. javaScript drag对象进行拖拽使用详解

    目录 drag简介 兼容性 drag事件 拖拽流程 DataTransfer对象 drag拖放桌面文件 drag实例 小结 drag简介 HMTL5提供的支持原生拖拽的实现 兼容性如何? 桌面端的支持 ...