Miaomiao's Geometry

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

Total Submission(s): 191    Accepted Submission(s): 38

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
 
Recommend
 

简直奇妙,比赛的时候900多就21个过的...,自己当时没考虑到一条线段能覆盖两个点的情况,说究竟还是自己太弱了,不够细心,还有就是自己太心急了,刚敲完就交了,导致罚时比較多,今后得慢慢改,注意到答案仅仅能是距离或者距离的一半,依次枚举即可,对每一个点仅仅有两种选择,一种是选点左边的线段,一种是选右边的线段,当能选左边的时候一定要选左边的,否则选右边的,如果左右两边都不能选,那么这个线段肯定长了,如果当前枚举的距离为x,那么选左边的条件是A[j]-A[j-1]-vis[j]>=x||A[j]==A[j-1]+x,右边这样的就是一条线段覆盖两个点的情况,vis[j]是上一个点对如今这个区间的影响.

代码例如以下:

#include <iostream>
#include <map>
#include<algorithm>
#include <stack>
#include <string.h>
#include <queue>
#include<cstdio>
using namespace std;
#define INF 5e9+7
typedef long long LL;
int main()
{
//freopen("in.txt","r",stdin);
long long T,N;
double A[100];
double vis[100];
cin>>T;
while(T--)
{
cin>>N;
for(int i=1; i<=N; i++)cin>>A[i];
sort(A+1,A+N+1);
double ans=0;
A[N+1]=INF;
for(int i=1; i<=N-1; i++)
{
memset(vis,0,sizeof(vis));
double x=A[i+1]-A[i];
bool ok1=true,ok2=true;
for(int j=2; j<=N-1; j++)
{
if((A[j]-A[j-1]-vis[j]>=x)||(A[j]==A[j-1]+x))
{
continue;
}
if(A[j+1]-A[j]>=x)
{
vis[j+1]=x;
continue;
}
ok1=false;
break;
}
if(ok1)
{
ans=max(x,ans);
}
memset(vis,0,sizeof(vis));
for(int j=2; j<=N-1; j++)
{
if(A[j]-A[j-1]-vis[j]>=x/2||A[j]==A[j-1]+x/2)
{
continue;
}
if(A[j+1]-A[j]>=x/2)
{
vis[j+1]=x/2;
continue;
}
ok2=false;
break;
}
if(ok2)ans=max(ans,x/2);
}
printf("%.3f\n",ans);
}
return 0;
}

HDU 4932 贪心的更多相关文章

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

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

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

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

  3. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  4. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

  5. hdu 1735(贪心) 统计字数

    戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...

  6. hdu 4974 贪心

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...

  7. hdu 4982 贪心构造序列

    http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...

  8. HDU 2307 贪心之活动安排问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)  ...

  9. HDU 1052 贪心+dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...

随机推荐

  1. hdu 3635 Dragon Balls(加权并查集)2010 ACM-ICPC Multi-University Training Contest(19)

    这道题说,在很久很久以前,有一个故事.故事的名字叫龙珠.后来,龙珠不知道出了什么问题,从7个变成了n个. 在悟空所在的国家里有n个城市,每个城市有1个龙珠,第i个城市有第i个龙珠. 然后,每经过一段时 ...

  2. 《Python CookBook2》 第一章 文本 - 改变多行文本字符串的缩进 && 扩展和压缩制表符(此节内容待定)

    改变多行文本字符串的缩进 任务: 有个包含多行文本的字符串,需要创建该字符串的一个拷贝.并在每行行首添加或者删除一些空格,以保证每行的缩进都是指定数目的空格数. 解决方案: # -*- coding: ...

  3. Libsvm的MATLAB调用和交叉验证

    今天听了一个师兄的讲课,才发现我一直在科研上特别差劲,主要表现在以下几个方面,(现在提出也为了督促自己在以后的学习工作道路上能够避免这些问题) 1.做事情总是有头无尾,致使知识点不能一次搞透,每次在用 ...

  4. Python对象体系揭秘

    Guido用C语言创造了Python,在Python的世界中一切皆为对象. 一.C视角中的Python对象 让我们一起追溯到源头,Python由C语言实现,且向外提供了C的API http://doc ...

  5. ado.net(class0503)

    ado.net组成 数据提供程序 connection //连接对象 command executeNonQuery //执行增删改 executeScalar //执行查询返回首行首列 execut ...

  6. Matlab文件操作

    1.  Matlab文件操作主要有三个步骤:首先打开文件,然后对文件进行读写操作,最后要关闭文件. 2.  fid=fopen(文件名,打开方式) 'r' 只读,文件必须存在(缺省的打开方式) 'w' ...

  7. PHP:PHP5.4连接SQLSERVER

    在PHP5.4的环境下要连接SQLSERVER(2005/2008)数据库,需要以下步骤: 1.下载PHP5.4连接SQLSERVER的驱动(两个动态连接库)http://www.microsoft. ...

  8. hive优化之------控制hive任务中的map数和reduce数

    一.    控制hive任务中的map数: 1.    通常情况下,作业会通过input的目录产生一个或者多个map任务. 主要的决定因素有: input的文件总个数,input的文件大小,集群设置的 ...

  9. matplotlib绘制三维图

    本文参考官方文档:http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html 起步 新建一个matplotlib.figure.Figure对象, ...

  10. Jquery类级别与对象级别插件开发

    jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery命名空间的函数,另一种是对象级 ...