【题目链接】:http://codeforces.com/contest/527/problem/D

【题意】



一维线段上有n个点

每个点有坐标和权值两个域分别为xi,wi;

任意一对点(i,j)

如果|xi-xj|>=wi+wj

则在这两个点之间连一条边;

让你求最大团;

团就是任意两个点之间都有边相连;

【题解】



|xi-xj|>=wi+wj;

这里的绝对值直接去掉好了;

然后可以变形为

xi-wi>=xj+wj

(或者是xj-wj>=xi+wi也没差)

总之就是xi-wi如果比另外一个点的xj+wj来得大的话;

就能在这对点之间建立一条边;

按照这个规则

我们处理出每个点的

xi-wi和xi+wi;

记为p1域和p2域

把所有的点按照p2域升序排一下;

p2域相同的话,p1域随意;

然后选取第一个点p2域作为temp;

然后

for (i=2;i<=n;i++)
if (i->p1域>=temp)
{
temp = i->p2域;
ans++;
/*
这里因为i->p1域大于等于temp,所以这个点的p1域肯定也
大于之前的所有点,所以能和之前的所有点都建一条边,符合团的定义;
同时因为我们把p2域升序排了,所以遇到p1域大于temp的,直接选它肯定不会影响到后面的点的选取,因为如果你后面的点能选的话,肯定不及选这个点来得优秀,因为这个点的p2域比较小啊,你选后面那个点的也是只能给答案递增1,选这个也是只能给答案递增1,显然选p2域小一点的合适啊。因为这样为你"能够选到更多的点"做了贡献
*/
}

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5+100; struct abc
{
int xsw, xpw;
}; int n,temp,ans = 1;
abc a[N]; bool cmp(abc a, abc b)
{
return a.xpw < b.xpw;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
rep1(i, 1, n)
{
int x, w;
rei(x), rei(w);
a[i].xsw = x - w, a[i].xpw = x + w;
}
sort(a + 1, a + 1 + n, cmp);
temp = a[1].xpw;
rep1(i, 2, n)
{
if (a[i].xsw >= temp)
{
temp = a[i].xpw;
ans++;
}
}
printf("%d\n", ans);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 527D】Clique Problem的更多相关文章

  1. 【codeforces 793C】Mice problem

    [题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...

  2. 【codeforces 807D】Dynamic Problem Scoring

    [题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...

  3. 【26.09%】【codeforces 579C】A Problem about Polyline

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 749A】Bachgold Problem

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【Codeforces 1096D】Easy Problem

    [链接] 我是链接,点我呀:) [题意] 让你将一个字符串删掉一些字符. 使得字符串中不包含子序列"hard" 删掉每个字符的代价已知为ai 让你求出代价最小的方法. [题解] 设 ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. [codeforces 528]B. Clique Problem

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

  8. 【codeforces 798C】Mike and gcd problem

    [题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...

  9. 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. Silverlight 2学习笔记二:三个基本布局控件(Canvas、StackPanel、Grid )

    这篇文章主要是翻译了ScottGu博客的文章:Silverlight Tutorial Part 2: Using Layout Management.虽然是翻译,但通过笔记记录,我发现对这三个布局控 ...

  2. Python:SMOTE算法——样本不均衡时候生成新样本的算法

    Python:SMOTE算法 直接用python的库, imbalanced-learn imbalanced-learn is a python package offering a number ...

  3. 【转载】[Oracle] Linux下手动创建数据库过程

    今天发现一个Oracle测试库的字符集设置不正确,原本的字符集是UTF-8,正确的字符集应该是ZHS16GBK,因为UTF-8是ZHS16GBK的超集,无法修改,只能重建数据库,幸好该测试库上还没有数 ...

  4. 使用adb进行关机(转载)

    转自:http://hi.baidu.com/fangqianshu/item/dc52b92d31b2dd1542634a3d 其实进入adb shell,然后执行reboot -p或者直接在命令行 ...

  5. yum 安装redis

    1.yum install redis 2.yum install php-redis 3service redis start chkconfig redis on

  6. WCF 通讯标准绑定

    WCF 通讯标准绑定 一.预定义标准绑定 标准绑定 说明 BasicHttpBinding BasicHttpBinding 绑定用于最广泛的互交操作,针对第一代Web服务,所使用的传输协议是HTTP ...

  7. Context的正确使用

    一.Context的作用 Context的最大作用就是我们可以通过传递它来获得其他Activity或Application的相关资源和方法,它就相当于它们的引用,我们通过引用来获得对象的封装,这也是我 ...

  8. 【Codeforces1109B_CF1109B】Sasha and One More Name(字符串)

    题目: Codeforces1109B 我打的是 Div2 ,所以我看到的题号实际上是 1113D -- 考场上傻了没敢大力猜结论没做出来这道题,不幸掉分-- 1869->1849 嘤嘤嘤 翻译 ...

  9. 题解报告:hdu 1233 还是畅通工程

    Problem Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能 ...

  10. 347 Top K Frequent Elements 前K个高频元素

    给定一个非空的整数数组,返回其中出现频率前 k 高的元素.例如,给定数组 [1,1,1,2,2,3] , 和 k = 2,返回 [1,2].注意:    你可以假设给定的 k 总是合理的,1 ≤ k ...