题目链接:

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
3
3
1 2 3
3
1 2 4
4
1 9 100 10
 
Sample Output
1.000
2.000
8.000
Hint
For the first sample , a legal answer is [1,2] [2,3] so the length is 1.
For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2.
For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8.
 
Source
 

题意:

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

思路:

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

代码例如以下:

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 147;
int f[MAXN];//记录线段方向
double p[MAXN];
double d[MAXN];//相邻断点的差值
int n;
void init()
{
memset(p,0,sizeof(p));
memset(f,0,sizeof(f));
memset(d,0,sizeof(d));
} bool Judge(double tt)
{
int i;
for(i = 1; i < n-1; i++)
{
if(p[i] - tt < p[i-1] && p[i] + tt > p[i+1])
break;//不管向左还是向右均为不符合
if(p[i] - tt >= p[i-1])//向左察看
{
if(f[i-1] == 2)//假设前一个是向右的
{
if(p[i] - p[i-1] == tt)
f[i] = 1;//两个点作为线段的两个端点
else if(p[i] - p[i-1] >= 2*tt)//一个向左一个向右
{
f[i] = 1;
}
else if(p[i] + tt <= p[i+1])
{
f[i] = 2;//仅仅能向右
}
else
return false;
}
else
f[i] = 1;
}
else if(p[i] + tt <= p[i+1])
f[i] = 2;
}
if(i == n-1)//所有符合
return true;
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%lf",&p[i]);
}
sort(p,p+n);
int cont = 0;
for(int i = 1; i < n; i++)
{
d[cont++] = p[i] - p[i-1];
d[cont++] = (p[i] - p[i-1])/2.0;
}
sort(d,d+cont);
double ans = 0;
for(int i = cont-1; i >= 0; i--)
{
memset(f,0,sizeof(f));
f[0] = 1; //開始肯定是让线段向左
if(Judge(d[i]))
{
ans = d[i];
break;
}
}
printf("%.3lf\n",ans);
}
return 0;
}

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. 关于viewports 设备像素比 密度

    首先追溯到像素,第一个麻烦事像素的总量问题,同样的大小的屏幕像素可以差很远,像素大小更小的导致内容也变小   在小屏幕上如果展示巨大的桌面网页,诺基亚的做法是首先载入完整的桌面网页,然后缩放至设备屏幕 ...

  2. 关于Linux CentOS 7 时区时间修改问题

    原文:http://blog.csdn.net/yin138/article/details/52765089 今天遇到时区的问题,操作系统为CentOS 7 1. 首先进入终端,使用su root ...

  3. Pycharm,Python原生IDE?

    老套路,安装和使用(Win7x64.JDK神马滴早已装好). 1.安装 网上下下来后就这东西 Next D盘路径 我选择.我喜欢 开装 好慢,以后用光纤 O了 桌面小图标 2.使用 以管理员身份打开软 ...

  4. SSM 五:Spring核心概念

    第五章:Spring核心概念 一.Spring Ioc 优点: 1.低侵入式设计 2.独立于各种应用服务器 3.依赖注入特性将组建关系透明化,降低耦合度 4.面向切面编程的特性允许将通用性任务集中式处 ...

  5. 使用MS Test做单元测试

    声明:本篇博客翻译自:http://www.c-sharpcorner.com/article/unit-testing-with-ms-tests-in-c-sharp/ 写在翻译之前: 依然清晰的 ...

  6. java-基础-泛型

    java泛型通配符问题.   java中的泛型基本用法参考<java编程思想>第四版 p.353 java泛型中比较难理解的主要是类型擦除和通配符相关.   1.类型擦除 在编译期间,类型 ...

  7. Zuul(SpringCloud学习笔记一)

    路由是微服务架构中必须(integral )的一部分,比如,"/" 可能映射到你的WEB程序上,"/api/users "可能映射到你的用户服务上," ...

  8. 2810:完美立方-poj

    2810:完美立方 总时间限制:  1000ms 内存限制:  65536kB 描述 形如a3= b3 + c3 + d3的等式被称为完美立方等式.例如123= 63 + 83 + 103 .编写一个 ...

  9. Beautifulsoup分解

    from urllib.request import Request, ProxyHandler from urllib.request import build_opener from bs4 im ...

  10. 爬虫day 04_01(爬百度页面)

    import urllib.request import http.cookiejar from lxml import etree head = { 'Connection': 'Keep-Aliv ...