Miaomiao's Geometry
HDU 4932 Bestcoder
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.
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.
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.
#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的更多相关文章
- BestCoder Round #4 之 Miaomiao's Geometry(2014/8/10)
最后收到邮件说注意小数的问题!此代码并没有过所有数据,请读者参考算法, 自己再去修改一下吧!注意小数问题! Miaomiao's Geometry Time Limit: 2000/1000 MS ( ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- hdu4932 Miaomiao's Geometry
这是一道搜索题,我们很容易得到目标值的上下界,然后就只能枚举了. 就是将x轴上的点排序之后从左到右依次考察每个点,每个点要么在线段的左端点,要么在线段的右端点. 点编号从0到n-1,从编号为1的点开始 ...
- 【HDOJ】4932 Miaomiao's Geometry
递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. #include <cstdio> #include <cstring> #incl ...
- BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...
- HDU 4932 Miaomiao's Geometry(推理)
HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...
- hdu 4932 Miaomiao's Geometry(暴力)
题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...
- hdu4932 Miaomiao's Geometry (BestCoder Round #4 枚举)
题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...
- hdu 4932 Miaomiao's Geometry(暴力枚举)
pid=4932">Miaomiao's Geometry ...
随机推荐
- 题目1434:今年暑假不AC (项目安排类:结束时间快排,判断开始时间)
题目描述: “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@#$%^&*%...”确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视作为 ...
- Oracle创建用户及表空间 代码片段
create tablespace testdatalogging datafile 'D:\oracle\oradata\orcl\testdata.dbf' size 50m autoextend ...
- (转载)Java之外观模式(Facade Pattern)
1.概念 为子系统中的一组接口提供一个统一接口.Facade模式定义了一个高层接口,这个接口使得这子系统更容易使用. 2.UML 3.代码 下面是一个具体案例的代码: package facade; ...
- UVALive 7456 Least Crucial Node (并查集)
Least Crucial Node 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/C Description http://7 ...
- [iOS基础控件 - 6.9.2] 静态单元格 QQ功能列表
使用storyboard设计静态的表格数据 A.实现步骤 1.控制器继承UITableViewController 2.在storyboard中使用TableViewController,删除原来 ...
- 转载yield关键字理解
实现IEnumerable接口及理解yield关键字 [摘要]本文介绍实现IEnumerable接口及理解yield关键字,并讨论IEnumerable接口如何使得foreach语句可以使用. 本 ...
- Map 排序
/** * 通过map 的 value 排序,并返回排序后的第一个条目 * * @param m 待排序集合 * @param desc true:降序排序,false:升序排序 * @return ...
- java实现简单的素数判断
素数的这个问题由来已久,大学刚接触语言的时候遇到过找素数的问题,找工作笔试的时候也遇到过素数的问题,今天就特地写这篇博文,缅怀一下. 一.什么是素数? 除了1和它本身以外不再有其他的除数整除. 二.判 ...
- mysql5.5主从配置
mysql主从同步# 一:mysql数据库的主从 mysql数据库5.5之后的版本和5.5以前的版本数据库主从存在差异,这里是针对数据库5.5之后的配置. 1.主库编辑my.cnf(linux的my. ...
- Oracle RMAN 清除归档日志
在开发环境及UAT环境经常碰到需要清除归档日志的情形,对于这个问题方法有很多.可以直接使用rm方式清除归档日志,也可以使用find命令来查找符合条件的记录来清除归档日志,或者直接写个shell脚本来搞 ...