【题目链接】: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;

然后

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

【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define ps push_back
  10. #define fi first
  11. #define se second
  12. #define rei(x) scanf("%d",&x)
  13. #define rel(x) scanf("%lld",&x)
  14. #define ref(x) scanf("%lf",&x)
  15. typedef pair<int, int> pii;
  16. typedef pair<LL, LL> pll;
  17. const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
  18. const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
  19. const double pi = acos(-1.0);
  20. const int N = 2e5+100;
  21. struct abc
  22. {
  23. int xsw, xpw;
  24. };
  25. int n,temp,ans = 1;
  26. abc a[N];
  27. bool cmp(abc a, abc b)
  28. {
  29. return a.xpw < b.xpw;
  30. }
  31. int main()
  32. {
  33. //freopen("F:\\rush.txt", "r", stdin);
  34. rei(n);
  35. rep1(i, 1, n)
  36. {
  37. int x, w;
  38. rei(x), rei(w);
  39. a[i].xsw = x - w, a[i].xpw = x + w;
  40. }
  41. sort(a + 1, a + 1 + n, cmp);
  42. temp = a[1].xpw;
  43. rep1(i, 2, n)
  44. {
  45. if (a[i].xsw >= temp)
  46. {
  47. temp = a[i].xpw;
  48. ans++;
  49. }
  50. }
  51. printf("%d\n", ans);
  52. //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
  53. return 0;
  54. }

【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. tiny4412学习(三)之移植linux-4.x驱动(1)支持网卡驱动【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74160686 一.思路 上一节我们通过DNW将内核.文件系统.设备树文件烧入到内 ...

  2. ajax异步文件上传和进度条

    一.ajax异步文件上传 之前有说过在form表单内的文件上传,但是会刷新页面,下面就来实现不刷新页面的异步文件上传 <div class="uploding_div"> ...

  3. 虚拟化技术概要之VMM结构

    1. 概述 当前主流的 VMM (Virtual Machine Monitor) 实现结构可以分为三类: 宿主模型 (OS-hosted VMMs)Hypervisor 模型 (Hypervisor ...

  4. SQL Server 数据字典生成脚本

    SELECT sysobjects.name AS 表名称 ,--sysproperties.[value] AS 表说明 ,syscolumns.name AS 字段名称 ,--properties ...

  5. css - 所有的a标签设置为新窗口打开

    前言 由于工作的需要,需要把某个页面下的所有a标签都设置为新开新窗口,即:<a href="XXX">增加target:<a href="XXX&quo ...

  6. Mysql中date,time,datetime,timestamp的区别

    区别: timestamp:时间戳.北京时间1970年01月01日08时00分00秒 起至现在的总秒数. datetime:带时分秒的完整时间,例如:1970-01-01 10:00:00 date: ...

  7. datatable 的使用方法

    遍历datatable的方法 +方法一:DataTable dt = dataSet.Tables[0];for(int i = 0 ; i < dt.Rows.Count ; i++){str ...

  8. jQuery 事件 - trigger() 方法 和 triggerHandler() 方法

    trigger() 方法触发被选元素的指定事件类型. triggerHandler() 方法触发被选元素的指定事件类型.但不会执行浏览器默认动作,也不会产生事件冒泡. triggerHandler() ...

  9. weak看iOS面试

    2013年 面试官:代理用weak还是strong? 我 :weak . 面试官:明天来上班吧 2014年 面试官:代理为什么用weak不用strong? 我 : 用strong会造成循环引用. 面试 ...

  10. 知识记忆1:标志寄存器PSW

    8086CPU的flag寄存器结构如下: [ ] [ ] [ ] [ ] [OF][DF][IF][TF][SF][ZF][ ][AF][ ][PF][ ][CF] 其中debug中的显示为: 标志 ...