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, ...
随机推荐
- 【Spring】IOC
浅谈IOC IOC的理论背景 图1:传统系统中,对象之间相互引用的一幅图,在采用面向对象方法设计的软件系统中,它的底层的实现都是由n个对象所组成的,所有的对象通彼此之间的合作最终实现系统的业务逻辑,如 ...
- bootstrap 字体颜色 对齐方式
一:字体代码:作用--颜色 1..text-muted:提示--浅灰色 2..text-primary:主要--蓝色 3..text-success:成功--浅绿色 4..text-info: ...
- 【Caffe】Ubuntu16.04上配置安装caffe(Only CPU)
一.首先看看自己的系统,Ubuntu16.04,cpu,没有Nvidia,没有opencv 二.安装依赖包 安装protobuf,leveldb,snappy,OpenCV,hdf5, protobu ...
- Linux 通过cksum 来判断文件是否是相同
1. 最近scp部署文件时 发现日期会发生变化 (刚查了下 可以使用 -p 命令进行处理) 会变成部署时的日期. 不好判断文件倒是有没有部署 2. 最简单的办法 我mount了 补丁服务器 到lin ...
- CDR真实图片转水墨画效果制作教程
CorelDRAW创造性滤镜组是最具有创造力的滤镜,使用里面的散开滤镜能够实现类似于水墨的表现手法,然后再结合图层的合并模式,让您的图片产生意想不到的视觉效果.本文将利用CorelDRAW软件中提供的 ...
- lsof command not found 解决
有些centos 没有 lsof命令,需要安装 yum install lsof -y 使用: lsof -i:端口号
- 学不好Linux?我们分析看看正确的学习方法是什么-马哥教育
2018年里,Linux运维的职位数量和平均薪资水平仍然持续了去年的强劲增幅,比很多开发岗位涨的都快.从研究机构的数据来看,Linux职位数量和工资水平涨幅均在IT行业的前五之列,比去年的表现还要好一 ...
- Ansible 利用playbook批量部署mariadb
环境说一下 192.168.30.21 ansible 192.168.30.25 client1 192.168.30.26 client2 这里我的ansible环境已经部 ...
- 安装低版本django1.11出错
错误信息: File "C:\python3\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper ...
- react typescript 子组件调用父组件
//父组件 import * as React from 'react'import { Input } from 'antd'const Search = Input.Searchimport &q ...