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

    Access Token 在微信公众平台接口开发中,Access Token占据了一个很重要的地位,相当于进入各种接口的钥匙,拿到这个钥匙才有调用其他各种特殊接口的权限. access_token是公 ...

  2. APACHE如何里一个站点绑定多个域名?用ServerAlias

    APACHE2如何里一个站点绑定多个域名?用ServerAlias以前很笨,要使多个域名指向同一站点总是这样写: <VirtualHost *:80>ServerAdmin i@kuigg ...

  3. JavaScript——对this指针的新理解

    一直以来对this的理解只在可以用,会用,却没有去深究其本质.这次,借着<JavaScript The Good Parts>,作了一次深刻的理解.(所有调试都可以在控制台中看到,浏览器F ...

  4. Spring4整合Hibernate4详细示例

    1. Spring整合Hibernate,主要是解决什么问题? a.让Spring提供的IOC容器来管理Hibernate的SessionFactory b.让Hibernate使用Spring提供的 ...

  5. vim MiniBufExplorer 插件

    MiniBufExplorer安装好久了,但一直没怎么使用过. 今天查了下资料,作为一个备份. 当你只编辑一个buffer的时候MiniBufExplorer派不上用场, 当 你打开第二个buffer ...

  6. JDBC学习笔记(2)——Statement和ResultSet

    Statement执行更新操作 Statement:Statement 是 Java 执行数据库操作的一个重要方法,用于在已经建立数据库连接的基础上,向数据库发送要执行的SQL语句.Statement ...

  7. (转)在iOS中使用icon font

    http://ued.taobao.org/blog/?p=8579 在开发阿里数据iOS版客户端的时候,由于项目进度很紧,项目里的所有图标都是用最平常的背景图片方案来实现.而为了要兼容普通屏与Ret ...

  8. Mybatis中实体类中的字段跟对应表的字段不一致时解决办法

    解决字段名与实体类属性名不相同的冲突 实体类字段: public class Order { private int id; private String orderNo; private float ...

  9. Google中rel="canonical"的相关解释和用法

    转载原地址 http://blog.sina.com.cn/s/blog_673b01740100jxlz.html 近听到很多SEO 对在页面的规范版本用规范 URL 标签( canonical U ...

  10. HDU4570----Multi-bit Trie----简单的DP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4570 题目意思: 给你N个数 要你分成多段,每段长度不能超过20 是的sum(ai*(2^bi))最小 ...