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.

终于结果仅仅可能出现两种情况,长度为某个区间长度,或为区间长度的一半。枚举每一个长度,仅仅要符合条件就更新最大值。

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int maxn = 1500;
const int MAX = 0x3f3f3f3f;
const int mod = 1000000007;
int t, n;
double a[55];
int ok(double cur) {
int vis = 0;
for(int i = 2; i < n ; i++) {
double l, r;
if(vis == 0) l = a[i]-a[i-1];
else l = a[i]-a[i-1]-cur;
if(l >= cur) vis = 0;
else {
r = a[i+1]-a[i];
if(r > cur ) vis = 1;
else if(r == cur) {
vis = 0;
i++;
}
else return 0;
}
}
return 1;
}
int main()
{
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lf", &a[i]);
sort(a+1, a+1+n);
double tmp ,ans = 0;
for(int i = 2; i <= n; i++) {
tmp = a[i]-a[i-1];
if(ok(tmp)) ans = max(ans, tmp);
tmp = (a[i]-a[i-1])/2;
if(ok(tmp)) ans = max(ans, tmp);
}
printf("%.3lf\n", ans);
}
return 0;
}



BestCoder Round #4 Miaomiao&#39;s Geometry (暴力)的更多相关文章

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

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

  2. hdu4932 Miaomiao&#39;s Geometry (BestCoder Round #4 枚举)

    题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...

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

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

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

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

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

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

  6. BestCoder Round #85 hdu5778 abs(素数筛+暴力)

    abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...

  7. BestCoder Round #75 King&#39;s Cake 模拟&amp;&amp;优化 || gcd

    King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...

  8. BestCoder Round #75 King&#39;s Order dp:数位dp

    King's Order Accepts: 381 Submissions: 1361 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 655 ...

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

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

随机推荐

  1. c的链接详解

    多目标文件的链接 stack.c #include <stdio.h> #define STACKSIZE 1000 typedef struct stack { int data[STA ...

  2. php之快速入门学习-2

    创建(声明)PHP 变量 PHP 没有声明变量的命令. 变量在您第一次赋值给它的时候被创建: <?php $txt="Hello world!"; $x=5; $y=10.5 ...

  3. interllij13新建maven web工程

    1. 打开intellij,左边的可以别管它(历史) ②选择create new project(新建一个项目),选择Maven,并选择一个web模板,然后next. 3. 给自己的项目取名,grou ...

  4. jdbc第二天

    事务 l 连接池 l ThreadLocal l BaseServlet自定义Servlet父类(只要求会用,不要求会写) l DBUtils à commons-dbutils 事务 l 事务的四大 ...

  5. 获取TrustedInstaller

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\runas] @="获取TrustedInstaller权限& ...

  6. webservice系统学习笔记5-手动构建/发送/解析SOAP消息

    手动拼接SOAP消息调用webservice SOAP消息的组成: 1.创建需要发送的SOAP消息的XML(add方法为例子) /** * 创建访问add方法的SOAP消息的xml */ @Test ...

  7. repr

    >>> import datetime >>> today=datetime.datetime.now() >>> today datetime. ...

  8. Java中创建实例化对象的几种方式

    Java中创建实例化对象有哪些方式? ①最常见的创建对象方法,使用new语句创建一个对象.②通过工厂方法返回对象,例:String s =String.valueOf().(工厂方法涉及到框架)③动用 ...

  9. js removeChild

    removeChild():删除元素只能通过直接父元素删除,没有自删 1 <select id="city" size="6" style="w ...

  10. Python使用chardet包自动检测编码

    chardet:charset detection 一旦自动检测出编码,就可以解码了. 八种文件打开方式 w:一旦打开文件,文件内容就清空了 r:只读方式打开 a:追加方式打开 r+:先读后写 以上四 ...