B - Clique Problem

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

思路:其实问题能转换为一堆线段问你最多能挑出多少个线段使其两两不相交。。 对于一个点来说可以变成[x - wi, x + wi]这样一条线段。。

然后贪心取就好啦。

 #include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int>> using namespace std; const int N=2e5+;
const int M=1e4+;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9 + ; int n;
pii p[N];
int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) {
int x, w; scanf("%d%d", &x, &w);
p[i].first = x - w;
p[i].second = x + w;
}
sort(p + , p + + n);
stack<pii> st;
for(int i = ; i <= n; i++) {
if(st.empty()) st.push(p[i]);
else if(p[i].first >= st.top().second) st.push(p[i]);
else if(p[i].second < st.top().second) st.pop(), st.push(p[i]);
}
printf("%d\n", st.size());
return ;
}
/*
*/

Codeforces Round #296 (Div. 1) B - Clique Problem的更多相关文章

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

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

  3. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  4. Codeforces Round #367 (Div. 2) C. Hard problem

    题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...

  5. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  6. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

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

  8. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  9. Codeforces Round #361 (Div. 2) C.NP-Hard Problem

    题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. ...

随机推荐

  1. MT【196】整数个数

    设函数$f(x)=x^2-2ax+15-2a$的两个零点分别为$x_1,x_2$, 且在区间$(x_1,x_2)$上恰好有两个正整数,则实数$a$的取值范围______ 提示:$1<|x_1-x ...

  2. MT【82】凸函数

    评:对于(3)几何上来看要满足性质$P$图像来看必须下凸.这样区间中点$x=2$处不可能为最大.(4)的形式让我想起在证明算术几何平均不等式时历史上著名的柯西反向归纳证明:

  3. ZOJ1100 Mondriaan's Dream

    题目链接:QAQ 大致题意:有一个m行n列的矩阵,用1*2的骨牌(可横放或竖放)完全覆盖,骨牌不能重叠,有多少种不同的覆盖的方法? Solution: \(n,m\le11\),肯定是不能暴力的,又类 ...

  4. 【BZOJ1296】[SCOI2009]粉刷匠(动态规划)

    [BZOJ1296][SCOI2009]粉刷匠(动态规划) 题面 BZOJ 洛谷 题解 一眼题吧. 对于每个串做一次\(dp\),求出这个串刷若干次次能够达到的最大值,然后背包合并所有的结果即可. # ...

  5. 【BZOJ1090】[SCOI2003]字符串折叠(动态规划)

    [BZOJ1090][SCOI2003]字符串折叠(动态规划) 题面 BZOJ 洛谷 题解 区间\(dp\).设\(f[i][j]\)表示压缩\([i,j]\)区间的最小长度.显然可以枚举端点转移.再 ...

  6. 【Luogu P4149】[IOI2011]Race(点分治)

    自闭了几天后的我终于开始做题了..然后调了3h一道点分治板子题,调了一天一道IOI... 最后还是自己手造数据debug出来的... 这题一看:树上路径问题,已知路径长度求balabala,显然是点分 ...

  7. javaweb购物车实现的几种方式

    之前没有接触过购物车的东东,也不知道购物车应该怎么做,所以在查询了很多资料,总结一下购物车的功能实现. 查询的资料,找到三种方法: 1.用cookie实现购物车: 2.用session实现购物车: 3 ...

  8. bzoj千题计划293:bzoj3142: [Hnoi2013]数列

    http://www.lydsy.com/JudgeOnline/problem.php?id=3142 如果已知数列的差分数列a[1]~a[k-1] 那么这种差分方式对答案的贡献为 N-Σ a[i] ...

  9. Spring RedisTemplate操作-xml配置(1)

    网上没能找到全的spring redistemplate操作例子,故特意化了点时间做了接口调用练习,基本包含了所有redistemplate方法. 该操作例子是个系列,该片为spring xml配置, ...

  10. python学习笔记7-excel操作

    一.操作excel import xlwt book = xlwt.Workbook() #新建一个excel sheet = book.add_sheet('sheet1') #添加一个sheet页 ...