527D.Clique Problem
题解:
水题
两种做法:
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的更多相关文章
- 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 判断一维线段没有两辆相交的最大线段数量
这题说的是给了n个位置 在x轴上 每个位置有一个权值为wi,然后将|xi - xj|>=wi+wj ,满足这个条件的点建一条边,计算着整张图中有多少多少个点构成的子图,使得这个子图的节点数尽量的 ...
- 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 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- Codeforces Round #296 (Div. 1) B - Clique Problem
B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...
- 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 ...
- B. Clique Problem(贪心)
题目链接: B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 回溯法——最大团问题(Maximum Clique Problem, MCP)
概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent ...
随机推荐
- 映美FP-530K+打印发票卡纸
最近打发票卡纸了几次,只能作废掉,硬件不太好排查,卡纸都是在发票的中间位置,我在卡纸的时候观察了好几次,打开打印机盖子,直接裸露这样看里面的打印状况,目前发现了两种卡纸位置. 如图,一种是后面的黑色塑 ...
- 利用window.performance.timing进行性能分析
性能分析... window.performance.timing中相关属性语义: // .navigationStart 准备加载页面的起始时间 // .unloadEventStart 如果前一个 ...
- [OI]Noip 2018总结(普及)
考砸了,还有原谅我代码十分有限的可读性. 一个人的真正伟大之处就在于他能够认识到自己的渺小.——保罗 从一年前初一九月到现在18年10月接触OI已经有一年了.几次模拟赛也自我感觉良好,都过了一等的线, ...
- Go语言协程
协程的特点 1.该任务的业务代码主动要求切换,即主动让出执行权限 2.发生了IO,导致执行阻塞(使用channel让协程阻塞) 与线程本质的不同 C#.java中我们执行多个线程,是通过时间片切换来进 ...
- POJChallengeRound2 Tree 【数学期望】
题目分析: 我们令$G(x)$表示前$x$个点的平均深度,$F(x)$表示第$x$个点的期望深度. 有$F(x) = G(x-1)+1$,$G(x) = G(x-1)+\frac{1}{x}$ 所以答 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)
题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...
- js文件上传原理(form表单 ,FormData + XHR2 + FileReader + canvas)
目录 form表单上传 FormData + XHR2 + FileReader + canvas 无刷新本地预览压缩上传实例 目前实现上传的方式 浏览器小于等于IE9(低版本浏览器)使用下面的方式实 ...
- [再寄小读者之数学篇](2014-05-27 矩阵的迹与 Jacobian)
(from MathFlow) 设 $A=(a_{ij})$, 且定义 $$\bex \n_A f(A)=\sex{\cfrac{\p f}{\p a_{ij}}}. \eex$$ 试证: (1) $ ...
- windows下 cmd 界面的替代者 cmder 推荐!
介绍 http://cmder.net/ Portable console emulator for Windows Cmder is a software package created out o ...
- 【转】史上最详细的Composer安装tp5教程
http://www.thinkphp.cn/topic/52362.html Composer安装tp5教程1.下载composer先介绍几个网站Composer官网https://getcompo ...