hdu 4932 Miaomiao's Geometry(暴力枚举)
pid=4932">Miaomiao's Geometry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit:
65536/65536 K (Java/Others)
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.
3
3
1 2 3
3
1 2 4
4
1 9 100 10
1.000
2.000
8.000HintFor 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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
double b[120], c[60];
int flag[60];
int n, i, j, T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i = 0; i < n; i++)
scanf("%lf",&c[i]);
sort(c, c+n);
int m = 0;
for(i = 1; i < n; i++)
{
b[m++] = c[i] - c[i-1];
b[m++] = (c[i] - c[i-1]) / 2;
}
sort(b, b+m);
double ans;
for(i = m - 1; i >= 0; i--)
{
memset(flag, 0, sizeof(flag));
flag[0] = 1;
double tmp = b[i];
for(j = 1; j < n - 1; j++)
{
if(c[j] - tmp < c[j-1] && c[j] + tmp > c[j+1]) //往左往右都不行
break;
if(c[j] - tmp >= c[j-1])
{
if(flag[j-1] == 2) // 前一个往右
{
if(c[j] - c[j-1] == tmp) flag[j] = 1; //两个点作为线段的两个端点
else if(c[j] - c[j-1] >= 2 * tmp) flag[j] = 1; //一个往左。一个往右
else if(c[j] + tmp <= c[j+1]) flag[j] = 2; //仅仅能往右
else break;
}
else flag[j] = 1;
}
else if(c[j] + tmp <= c[j+1])
flag[j] = 2;
}
if(j == n - 1)
{
ans = tmp;
break;
}
}
printf("%.3lf\n", double(ans));
}
return 0;
}
hdu 4932 Miaomiao's Geometry(暴力枚举)的更多相关文章
- hdu 4932 Miaomiao's Geometry(暴力)
题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...
- HDU 4932 Miaomiao's Geometry(推理)
HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...
- hdoj 4932 Miaomiao's Geometry 【暴力枚举】
题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...
- hdu4932 Miaomiao's Geometry (BestCoder Round #4 枚举)
题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
- hdu 4082 Hou Yi's secret(暴力枚举)
Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- BestCoder Round #4 Miaomiao's Geometry (暴力)
Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- hdu 4968 Improving the GPA (水 暴力枚举)
题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10, ...
随机推荐
- [转]linux之pr命令
转自:http://www.bitscn.com/plus/view.php?aid=6638 本文介绍如何使用Linux的pr命令将大文件分割成多个页面进行打印,并在每个页面上加上标题. Linux ...
- sql 循环分割字符
DECLARE @Items VARCHAR(1000)='148' --待处理拼接字符串 --开始处理SET @Items=@Items+',' --必须追加“,”否则最后一个无法输出DECLARE ...
- unity之Rigidbody属性
Rigidbody属性 Mass表示物体的质量,数值类型为float,默认值为1.大部分物体的质量属性接近于0.1才符合日常生活感官感受,超过10 ,则失去了仿真效果. Drag表示平移阻力,其数值类 ...
- Tomcat服务器安装与第一个jsp网页程序
1.安装tomcat服务器之前需要,先安装相应版本的jdk,个人理解Tomcat的大部分功能是使用了java的 jdk jar包的. jdk包下载方式网上可以查到 下载完后可以解压到一个指定目录,并在 ...
- js post一个对象 在C#中怎么接收? 未解决
这个在C#中怎么接收?
- win10 ubuntu18双系统环境搭建
感谢前辈辛勤总结,根据这3篇文章成功配置了双系统 https://blog.csdn.net/qq_24624539/article/details/81775635 https://blog.csd ...
- CPU内部组成及原理
CPU,Central Processing Unit,翻译过来叫中央处理器.是一块超大规模的集成电路,是一台计算机的运算核心(Core)和控制核心( Control Unit).电脑中所有操作都由C ...
- 微信小程序animation
wxml <view class="background" animation="{{rotateData}}"> </view>< ...
- 前端领域的BEM到底是什么
前端领域的BEM到底是什么 BEM - Block Element Modfier(块元素编辑器) BEM方法确保每一个参加了同一网站开发项目的人,基于一套代码规范去开发,这样非常有利于团队成员理解彼 ...
- Js—innerHTML和innerText的区别
1.innerHTML属性和innerText属性 都是对元素的一个操作,简单讲,innerHTML可以在某种特定环境下重构某个元素节点的DOM结构,innerText只能修改文本值 在JavaScr ...