题目链接:

pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu.cn/showproblem.php?pid=4932

Miaomiao's Geometry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 410    Accepted Submission(s): 147

Problem Description
There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length.



There are 2 limits:



1.A point is convered if there is a segments T , the point is the left end or the right end of T.

2.The length of the intersection of any two segments equals zero.



For example , point 2 is convered by [2 , 4] and not convered by [1 , 3]. [1 , 2] and [2 , 3] are legal segments , [1 , 2] and [3 , 4] are legal segments , but [1 , 3] and [2 , 4] are not (the length of intersection doesn't equals zero), [1 , 3] and [3 , 4]
are not(not the same length).



Miaomiao wants to maximum the length of segements , please tell her the maximum length of segments.



For your information , the point can't coincidently at the same position.
 
Input
There are several test cases.

There is a number T ( T <= 50 ) on the first line which shows the number of test cases.

For each test cases , there is a number N ( 3 <= N <= 50 ) on the first line.

On the second line , there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
 
Output
For each test cases , output a real number shows the answser. Please output three digit after the decimal point.
 
Sample Input
  1. 3
  2. 3
  3. 1 2 3
  4. 3
  5. 1 2 4
  6. 4
  7. 1 9 100 10
 
Sample Output
  1. 1.000
  2. 2.000
  3. 8.000
  4. Hint
  5. For the first sample , a legal answer is [1,2] [2,3] so the length is 1.
  6. For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2.
  7. For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8.
  8.  
 
Source
 

题意:

求最大可以覆盖全部所给的点的区间长度(所给的点必须处于区间两端)。

思路:

答案一定是相邻点之间的差值或者是相邻点之间的差值除以2,那么把这些可能的答案先算出来。然后依次从最大的開始枚举进行验证就可以。

代码例如以下:

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5. const int MAXN = 147;
  6. int f[MAXN];//记录线段方向
  7. double p[MAXN];
  8. double d[MAXN];//相邻断点的差值
  9. int n;
  10. void init()
  11. {
  12. memset(p,0,sizeof(p));
  13. memset(f,0,sizeof(f));
  14. memset(d,0,sizeof(d));
  15. }
  16.  
  17. bool Judge(double tt)
  18. {
  19. int i;
  20. for(i = 1; i < n-1; i++)
  21. {
  22. if(p[i] - tt < p[i-1] && p[i] + tt > p[i+1])
  23. break;//不管向左还是向右均为不符合
  24. if(p[i] - tt >= p[i-1])//向左察看
  25. {
  26. if(f[i-1] == 2)//假设前一个是向右的
  27. {
  28. if(p[i] - p[i-1] == tt)
  29. f[i] = 1;//两个点作为线段的两个端点
  30. else if(p[i] - p[i-1] >= 2*tt)//一个向左一个向右
  31. {
  32. f[i] = 1;
  33. }
  34. else if(p[i] + tt <= p[i+1])
  35. {
  36. f[i] = 2;//仅仅能向右
  37. }
  38. else
  39. return false;
  40. }
  41. else
  42. f[i] = 1;
  43. }
  44. else if(p[i] + tt <= p[i+1])
  45. f[i] = 2;
  46. }
  47. if(i == n-1)//所有符合
  48. return true;
  49. return false;
  50. }
  51. int main()
  52. {
  53. int t;
  54. scanf("%d",&t);
  55. while(t--)
  56. {
  57. init();
  58. scanf("%d",&n);
  59. for(int i = 0; i < n; i++)
  60. {
  61. scanf("%lf",&p[i]);
  62. }
  63. sort(p,p+n);
  64. int cont = 0;
  65. for(int i = 1; i < n; i++)
  66. {
  67. d[cont++] = p[i] - p[i-1];
  68. d[cont++] = (p[i] - p[i-1])/2.0;
  69. }
  70. sort(d,d+cont);
  71. double ans = 0;
  72. for(int i = cont-1; i >= 0; i--)
  73. {
  74. memset(f,0,sizeof(f));
  75. f[0] = 1; //開始肯定是让线段向左
  76. if(Judge(d[i]))
  77. {
  78. ans = d[i];
  79. break;
  80. }
  81. }
  82. printf("%.3lf\n",ans);
  83. }
  84. return 0;
  85. }

hdu4932 Miaomiao&#39;s Geometry (BestCoder Round #4 枚举)的更多相关文章

  1. BestCoder Round #4 Miaomiao&#39;s Geometry (暴力)

    Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...

  2. HDU 4932 Miaomiao&#39;s Geometry(推理)

    HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...

  3. hdu 4932 Miaomiao&#39;s Geometry(暴力)

    题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...

  4. hdu 4932 Miaomiao&#39;s Geometry(暴力枚举)

    pid=4932">Miaomiao's Geometry                                                               ...

  5. hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】

    题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...

  6. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  7. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  8. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  9. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

随机推荐

  1. Java多线程synchronized关键字

    synchronized关键字代表着同步的意思,在Java中被synchronized修饰的有三种情况 1.同步代码块 //锁为objsynchronized(obj){ while(true){ i ...

  2. 使用GetThumbnailImage进行图片缩放操作

    /// <summary>        /// 获取等比例缩放图片的方法        /// </summary>        /// <param name=&q ...

  3. Visual Studio 2017开发环境的安装

    Visual Studio 2017是微软为了配合.NET战略推出的IDE开发环境,同时也是目前开发C#程序最新的工具,本节以Visual Studio 2017社区版的安装为例讲解具体的安装步骤. ...

  4. mysql存储过程--学习

    -- 存储过程示例一   inDROP DATABASE IF EXISTS tdemo;CREATE DATABASE tdemo CHARACTER SET=utf8; USE tdemo;CRE ...

  5. Java多线程与并发模型之锁

    这是一篇总结Java多线程开发的长文.文章是从Java创建之初就存在的synchronized关键字引入,对Java多线程和并发模型进行了探讨.希望通过此篇内容的解读能帮助Java开发者更好的理清Ja ...

  6. Python之random

    random 伪随机数生成模块.如果不提供seed,默认使用系统时间. 使用相同seed,可获得相同的随机数序列,常用于测试. >>> from random import * &g ...

  7. 激光相机数据融合(4)--KITTI数据集中matlab接口说明及扩展

    KITTI数据集接口已经提供了matlab接口,本篇将说明详细说明其应用并与PCL进行对接.PCL为C++点云处理语言库,详情可见:http://pointclouds.org/ 程序可以从官网下载, ...

  8. IIS发布网站浏览之后看到的是文件目录 & Internal Server Error 处理程序“ExtensionlessUrlHandler-ISAPI-4.0_64bit”在其模块列表中有一个错误模块“IsapiModule” 解决方法 & App_global.asax.pduxejp_.dll”--“拒绝访问。 ”

    Q:IIS发布网站浏览之后看到的是文件目录 A:它出现了一个说到.NET4.0 更高框架什么的错误,所以我将 .NTE CRL版本由4.0改为2.0了,改为2.0后就出现了只能浏览文件目录了.改为4. ...

  9. Golang源码探索(三) GC的实现原理

    Golang从1.5开始引入了三色GC, 经过多次改进, 当前的1.9版本的GC停顿时间已经可以做到极短. 停顿时间的减少意味着"最大响应时间"的缩短, 这也让go更适合编写网络服 ...

  10. Python StringIO与BytesIO、类文件对象

    StringIO与BytesIO StringIO与BytesIO.类文件对象的用途,应用场景,优.缺点. StringIO StringIO 是io 模块中的类,在内存中开辟的一个文本模式的buff ...