HDU 4932  Bestcoder

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.

 
 
注意本题的答案可能是某个相邻两点的距离差的一半。会有很多人考虑 不全面,所以适合作为cf和bf题目。
初次通过部分的数据的答案不会出现距离差的 一半,不然就不好hack了。
付一组数据
6
1 5 15 18 24
答案应该为5,而不是4
 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include<iostream>
#include<math.h> using namespace std; int main()
{
int cas,i,n,right,left;
double res,a[55],b[120];
cin>>cas;
while(cas--)
{
cin>>n;
int j=0;
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for(i=1;i<n;i++)
{
b[j++]=a[i]-a[i-1];
b[j++]=(a[i]-a[i-1]) /2 ;
}
sort(b,b+j);
int flag=0;
j=j-1;
res=(double)b[j]; while(1)
{
right =0; left=0;
flag=0;
for(i=1;i<n;i++)
{
if(i==n-1) continue;
if(a[i]-res<a[i-1] && a[i]+res>a[i+1])
{
flag=1;
break;
}
if(a[i]-res>=a[i-1])
{
if(right==1)
{
if(a[i]-a[i-1]==res) {left=1; right=0; }
else if(a[i]-a[i-1]>=2*res) { left=1; right=0; }
else if(a[i]+res<=a[i+1]) { left=0; right=1; }
else flag=1;
}
else { left=1; right=0; }
}
else if(a[i]+res<=a[i+1]) {
right=1;
left=0;
} }
if(flag==1) {
j--;
res=b[j];
}
else
{
printf("%.3lf\n",res);
break;
}
}
}
return 0;
}
 
 
 
 
 
 
 
 

Miaomiao's Geometry的更多相关文章

  1. BestCoder Round #4 之 Miaomiao's Geometry(2014/8/10)

    最后收到邮件说注意小数的问题!此代码并没有过所有数据,请读者参考算法, 自己再去修改一下吧!注意小数问题! Miaomiao's Geometry Time Limit: 2000/1000 MS ( ...

  2. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

  3. hdu4932 Miaomiao's Geometry

    这是一道搜索题,我们很容易得到目标值的上下界,然后就只能枚举了. 就是将x轴上的点排序之后从左到右依次考察每个点,每个点要么在线段的左端点,要么在线段的右端点. 点编号从0到n-1,从编号为1的点开始 ...

  4. 【HDOJ】4932 Miaomiao's Geometry

    递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. #include <cstdio> #include <cstring> #incl ...

  5. BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...

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

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

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

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

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

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

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

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

随机推荐

  1. AAC 格式分析

    一直在做一个语音项目,到了测试阶段,近来不是很忙,想把之前做的内容整理一下. 关于AAC音频格式基本情况,可参考维基百科http://en.wikipedia.org/wiki/Advanced_Au ...

  2. win7旗舰版通知windows不是正版副本解决方法

    原文转载http://www.cnblogs.com/simple_666/archive/2013/04/13/win7%E6%97%97%E8%88%B0%E7%89%88%E9%80%9A%E7 ...

  3. Tkinter教程之Text(1)篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811343 '''Tkinter教程之Text篇(1)''''''1.创建第一个Text''' ...

  4. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

  5. nova --debug image-list

    nova --debug image-list DEBUG (session:) REQ: curl -g -i -X GET http://liberty-aio:35357/v3 -H " ...

  6. poj 1543 Perfect Cubes(注意剪枝)

    Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14901   Accepted: 7804 De ...

  7. [iOS 多线程 & 网络 - 1.2] - 多线程GCD

    A.GCD基本使用 1.GCD的概念 什么是GCD全称是Grand Central Dispatch,可译为"牛逼的中枢调度器"纯C语言,提供了非常多强大的函数GCD的优势GCD是 ...

  8. freemaker遍历嵌套list的map

    <#if disMap?exists> <#list disMap?keys as key> <#if ((disMap[key]))??&&((disM ...

  9. hibernateTemplate HibernateDaoSupport不建议在Spring与Hibernate整合中使用

    HibernateTemplate类属于spring框架中的类 :org.springframework.orm.hibernate3.HibernateTemplate HibernateTempl ...

  10. wikioi 1214 线段覆盖

    题目描述 Description 给定x轴上的N(0<N<100)条线段,每个线段由它的二个端点a_I和b_I确定,I=1,2,--N.这些坐标都是区间(-999,999)的整数.有些线段 ...