pid=4932">Miaomiao's Geometry

                                                                             Time Limit: 2000/1000 MS (Java/Others)    Memory Limit:
65536/65536 K (Java/Others)

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.
 
题意:给出n个点,找出一些等长的线段覆盖这些点。这些点仅仅能作为线段的端点,并且随意两条线段的相交长度不能大于0.求满足条件的线段的最大长度。
分析:通过分析能够得出。终于结果是相邻两点之间的长度,或者相邻两点之间长度的一半。由于最多仅仅有50个点,100个长度,所以仅仅需枚举这些长度。求出一个满足条件的最长线段就可以。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
double b[120], c[60];
int flag[60];
int n, i, j, T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i = 0; i < n; i++)
scanf("%lf",&c[i]);
sort(c, c+n);
int m = 0;
for(i = 1; i < n; i++)
{
b[m++] = c[i] - c[i-1];
b[m++] = (c[i] - c[i-1]) / 2;
}
sort(b, b+m);
double ans;
for(i = m - 1; i >= 0; i--)
{
memset(flag, 0, sizeof(flag));
flag[0] = 1;
double tmp = b[i];
for(j = 1; j < n - 1; j++)
{
if(c[j] - tmp < c[j-1] && c[j] + tmp > c[j+1]) //往左往右都不行
break;
if(c[j] - tmp >= c[j-1])
{
if(flag[j-1] == 2) // 前一个往右
{
if(c[j] - c[j-1] == tmp) flag[j] = 1; //两个点作为线段的两个端点
else if(c[j] - c[j-1] >= 2 * tmp) flag[j] = 1; //一个往左。一个往右
else if(c[j] + tmp <= c[j+1]) flag[j] = 2; //仅仅能往右
else break;
}
else flag[j] = 1;
}
else if(c[j] + tmp <= c[j+1])
flag[j] = 2;
}
if(j == n - 1)
{
ans = tmp;
break;
}
}
printf("%.3lf\n", double(ans));
}
return 0;
}

hdu 4932 Miaomiao&#39;s Geometry(暴力枚举)的更多相关文章

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

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

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

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

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

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

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

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

  5. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

  6. hdu 4082 Hou Yi's secret(暴力枚举)

    Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. 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 ...

  8. HDU 5944 Fxx and string(暴力/枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  9. hdu 4968 Improving the GPA (水 暴力枚举)

    题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10, ...

随机推荐

  1. C# linq学习【转】

    在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前, 我们在声明一个变量的时候, 总是要为一个变量指定他的类型 甚至在fore ...

  2. Google广告屏蔽插件adBlock

    今天在博客园写博客的时候发现莫名其妙的在右侧被植入了广告,询问了管理员得知存在以下几种可能: 1.电信网络供应商劫持网页,植入广告 2.ADSafe(是一款去除广告的软件,效果很不错) 但经过最终排除 ...

  3. 消息队列 (2) java实现简单的RabbtMQ

    假设有如下问题: 1.如果消费者连接中断,这期间我们应该怎么办? 2.如何做到负载均衡? 3.如何有效的将数据发送到相关的接收者?就是怎么样过滤 4.如何保证消费者收到完整正确的数据 5.如何让优先级 ...

  4. MVC系列学习(十一)-客户端的验证

    1.通过一个实例,来了解MVC中强大的验证功能 1.1新建一个 [基本] 的mvc项目,因为要用到验证的js,然后在一个视图中写上一下代码,以及Model中的代码如下 [注]在调用html.EditF ...

  5. 实现strcpy

    #include <stddef.h> char* strcpy(char* dest, const char* src) { if (dest == NULL || src == NUL ...

  6. 对“空引用”说bye-bye

    大家可能经常遇到这种情况:当一个对象为null时,调用这个对象的方法或者属性时,就会报错:“Object reference not set to an instance of an object.” ...

  7. 去除IOS苹果手机自带按钮样式的问题~

    input[type="button"], input[type="submit"], input[type="reset"] { -web ...

  8. html——行内元素、块元素、行内块元素

    行内元素:span  ,a,  ,strong , em,  del,  ins.特点:在一行上显示:不能直接设置宽高:元素的宽和高就是内容撑开的宽高. 块元素:div,h1-h6,p,ul,li.特 ...

  9. CSS之float浮动

    CSS理解之float浮动 首先我们看看W3C给出的关于 float 的说明: 参考资料   MDN   W3C

  10. php base64互转pdf

    /* * base64转pdf */ function base642pdf($formTxt,$toPdf) { $file = file_get_contents($formTxt);//读 $d ...