题解:

水题

两种做法:

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. PhotoShop不用魔棒、钢笔 建立较平整的选区 P进电脑屏幕里

    不用魔棒.抽出.钢笔等,还可以直接变形图建立调整选区,这种方法比钢笔抽出感觉简单一些,比魔棒仔细一些. 抽出或钢笔:抽出弄错了偏移了还要擦除,调整笔刷,抽出后可能还有毛边,需要用橡皮擦除: 钢笔,错了 ...

  2. HTTP简明学习

    前面的话 本文将详细介绍HTTP主要内容 概述 Web 的诞生,源于三大技术的诞生,它们都是当年 Web 之父 Tim Berners-Lee 自己 开发的,世界上第一个网站诞生的时间是 1991 年 ...

  3. python之数据类型补充、集合、深浅copy

    一.内容回顾 代码块: 一个函数,一个模块,一个类,一个文件,交互模式下,每一行就是一个代码块. is == id id()查询对象的内存地址 == 比较的是两边的数值. is 比较的是两边的内存地址 ...

  4. Sublime怎么安装Package control组件

    Sublime怎么安装Package control组件 藏色散人 藏色散人 2018-11-26 14:30:51 原创 Sorry, your browser does not support e ...

  5. Elastic Search 语法总结

    1. 插入 PUT /megacorp/employee/1 { "first_name" : "John", "last_name" : ...

  6. xadmin后台 导入 excel 功能拓展

    新建 excel 文件 在 xadmin 的 plugins 下添加一个 excel.py # _*_ coding:utf-8 _*_ __author__ = "yangtuo" ...

  7. LoadRunner【第五篇】关联

    关联的定义及使用场景 关联:将服务器提供动态变化的值存放在变量中,当需要使用该变量时,由LoadRunner自动从服务器响应的信息中获取该值,并在后面使用的过程中进行替换.(也可能是前端页面动态生成的 ...

  8. DP擎天

    DP! 黄题: 洛谷P2101 命运石之门的选择 假装是DP(分治 + ST表) CF 982C Cut 'em all! 树形贪心 洛谷P1020 导弹拦截 单调队列水题 绿题: 洛谷P1594 护 ...

  9. 搭建vsf

    参考: 1.https://blog.csdn.net/liuzhenwen/article/details/7026263 我是全部替换了/lib/为/lib64/ 2.https://blog.c ...

  10. 什么是javabean及其用法(转)

    因工作需要 需要学习jsp方面的知识 这篇博客文章写得比较全面 我记录下: 一.什么是JavaBean JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个 ...