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 3038 How Many Answers Are Wrong(种类并查集)2009 Multi-University Training Contest 13

    了解了种类并查集,同时还知道了一个小技巧,这道题就比较容易了. 其实这是我碰到的第一道种类并查集,实在不会,只好看着别人的代码写.最后半懂不懂的写完了.然后又和别人的代码进行比较,还是不懂,但还是交了 ...

  2. 开启Ubuntu Linux下VirtualBox访问USB功能

    解决方法如下: 1.增加用户组usbfs sudo groupadd usbfs 2.查看usbfs用户组的gid cat /etc/group | grep usbfs usbfs:x:1002: ...

  3. Stamps and Envelope Size

    题意: 容量为s的信封,给n组邮票的面值,求哪一组能组成的连续的面值的最大值最大,若有多组答案,输出面值数量最小的一组,若数量相等,输出最大面值最小的一组,若最大面值相等,输出第二大面值最小的一组,依 ...

  4. poj1247 bjfu1239水题

    其实就是读题啦,读懂题很简单,就是问一个数组,存不存在一个点,按这个点切成两半,这两半的数字的和是一样的.不多说了,上代码 /* * Author : ben */ #include <cstd ...

  5. Allegro从.brd文件中导出器件封装

    打开.brd文件,File→Export→Libraries,除了No libraries dependencies之外,所有选项都勾选上,设定好存放路径之后,Export. 注意事项: 1. 一般的 ...

  6. 【STL】帮你复习STL泛型算法 一

    STL泛型算法 #include <iostream> #include <vector> #include <algorithm> #include <it ...

  7. 游戏设计模式:Subclass Sandbox模式,以及功能方法集的设计思考

    书中总结出这种 Subclass Sandbox 的设计模式 Game Design Patterns: Subclass Sandbox 这种模式要点有两点: 在基类中实现各种功能性方法供子类调用 ...

  8. MVC中CheckBox

    一.单个Checkbox 1.View文件 <%= Html.CheckBoxFor(model => model.IsNeverExpired)%> 2.生成的HTML为 < ...

  9. Java每日一则-002

    Java中包的层级关系 java中的包在逻辑上是没有套嵌的,也就是说: java.lang 和 java.lang.awt 是两个平行的包,地位相等,互不相关.只不过一个名字叫java.lang另一个 ...

  10. POJ No.3680 Intervals

    2016-06-01 22:01:39 题目链接: POJ No.3680 Intervals 题目大意: 给定N个带权区间,最多可以重复选一个点M次,求出一种选法使得所得权最大 解法: 费用流 建模 ...