BestCoder Round #4 Miaomiao's Geometry (暴力)
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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int maxn = 1500;
const int MAX = 0x3f3f3f3f;
const int mod = 1000000007;
int t, n;
double a[55];
int ok(double cur) {
int vis = 0;
for(int i = 2; i < n ; i++) {
double l, r;
if(vis == 0) l = a[i]-a[i-1];
else l = a[i]-a[i-1]-cur;
if(l >= cur) vis = 0;
else {
r = a[i+1]-a[i];
if(r > cur ) vis = 1;
else if(r == cur) {
vis = 0;
i++;
}
else return 0;
}
}
return 1;
}
int main()
{
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lf", &a[i]);
sort(a+1, a+1+n);
double tmp ,ans = 0;
for(int i = 2; i <= n; i++) {
tmp = a[i]-a[i-1];
if(ok(tmp)) ans = max(ans, tmp);
tmp = (a[i]-a[i-1])/2;
if(ok(tmp)) ans = max(ans, tmp);
}
printf("%.3lf\n", ans);
}
return 0;
}
BestCoder Round #4 Miaomiao's Geometry (暴力)的更多相关文章
- 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 ...
- hdoj 4932 Miaomiao's Geometry 【暴力枚举】
题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...
- HDU 4932 Miaomiao's Geometry(推理)
HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...
- BestCoder Round #85 hdu5778 abs(素数筛+暴力)
abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...
- BestCoder Round #75 King's Cake 模拟&&优化 || gcd
King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- BestCoder Round #75 King's Order dp:数位dp
King's Order Accepts: 381 Submissions: 1361 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 655 ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
随机推荐
- 基于redis分布式锁实现“秒杀”(转载)
转载:http://blog.csdn.net/u010359884/article/details/50310387 最近在项目中遇到了类似“秒杀”的业务场景,在本篇博客中,我将用一个非常简单的de ...
- 你的灯亮着吗pdf –读书笔记
十句话概括这本书 1.确认问题比找到方法更重要 2.解决问题其实解决的是"人的期待" 3.你在解决问题中可能会发现新的机会 4.要了解问题的可变性和复杂性 5.站在用户而不 ...
- PHP 循环
PHP 中的循环语句用于执行相同的代码块指定的次数. 循环 在您编写代码时,您经常需要让相同的代码块运行很多次.您可以在代码中使用循环语句来完成这个任务. 在 PHP 中,我们可以使用下列循环语句: ...
- 【VMware】宿主机连接wifi,虚拟机中的Linux系统配置连接wifi
环境描述 宿主机:Windows 10 64bit 虚拟机:Centos 第一步:虚拟机设置 选择连接方式为NAT 第二步:设置宿主机的wifi 控制面板>>网络和Internet> ...
- windows上安装db2 spatial extender和ArcSDE的问题
因客户的DB2版本是9.7的版本,所以测试环境也只能安装这个版本,但在ArcSDE的最小支持版本里至少需要V9.7 pack 4的版本,低于这个版本是不行的. 安装DB2和spatial extend ...
- Redis学习(3)-redis启动
前端启动 tomcat,redis,mysql的端口号: mysql 3306 tomcat 8088 redis 6379 一,启动redis服务: 例如当前位置在redis安装目录下面: 启动re ...
- iOS-各种动画特效
概述 广播跑马灯/弹幕/直播点赞/烟花/雪花等动画特效, 后续增加~ 详细 代码下载:http://www.demodashi.com/demo/10674.html 一.实现功能 1. 广播跑马灯 ...
- MSSQL-SQL SERVER 分页原理
项目中用到的, 用心琢磨一下此SQL语句即可: SELECT TOP $row * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [ID] desc ...
- 面试题 Comparable、Comparator 比较
Comparable 用作默认的比较方式 Comparator 用作自定义的比较方式,当默认的比较方式不适用时或者没有提供默认的比较方式,使用Comparator就非常有用. 像Arrays和Coll ...
- [ubuntu]为ubuntu设立“任务管理器”的组合键
在windows下面,我们可以方便的使用ctrl+alt+delete调出任务管理器,那么在ubuntu下面如何实现呢?这里我们介绍两种方法:1.在终端下运行: 代码:gconf-editor 找到: ...