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 ...
随机推荐
- 【转】TCP/IP详解学习笔记(一)
TCP/IP详解学习笔记 这位仁兄写得太好了. http://blog.csdn.net/goodboy1881/category/204448.aspx TCP/IP详解学习笔记(13)-T ...
- LoadRunner 测试 Mysql
准备文件 1. 下载 MySQL LoadRunner libraries. 下载地址:http://files.cnblogs.com/files/xiaoxitest/MySQL_LoadRunn ...
- Java从零开始学九(数组)
一.什么是数组 数组是一组相关数据的集合,一个数组实际上就是一连串的变量,数组按照使用可以分为一维数组.二维数组.多维数组.同一数组中的变量数据类型相同 二.数组的优点 不使用数组定义100个整型变量 ...
- STM32F429I-DISCO 和GPS的亲热接触
第27章 GPS LCD显示教程 本期教程为大家解说GPS Global Positioning System(全球定位系统)的使用,.GPS是由美国国防部研制建立的一种具有全方位.全天候.全时段.高 ...
- 递归和for循环
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.cnblogs.com/BeginMan/p/3223356.html #递归2 '非 ...
- 使用loadrunner对https协议(单双向SSL)的web端性能测试 (转)
1.项目背景 1.1 单双向SSL的含义及部署 单向SSL即我们说到的https协议. 特点是,浏览器需要请求验证服务器证书: 基本含义是:一个安全通信通道,它基于HTTP开发,用于在客户计算机和服务 ...
- 启动ip wizard时报the ip wizard does not support dhcp
启动ip wizard时报the ip wizard does not support dhcp 阅读:5502012-05-11 11:15 标签:loadrunner 打开ip wizard:开始 ...
- 【laravel5.4】PHP5.6+ 调用命名空间下类方法、属性和对象
1.调用命名空间的类方法,对象.属性 类对象:\App\User(); 类方法:\App\User::find($this->user_id) //查询构造器方法,将$this->user ...
- eclipse里没有project facets
我下载的eclipse版本问题,导入maven工程可以显示Dynamic web Module. 新建maven工程之后,点击工程属性里没有project facets,从而没有配置Dynamic w ...
- HDUOJ-----2852 KiKi's K-Number(树状数组+二分)
KiKi's K-Number Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...