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 ...
随机推荐
- 【IPC进程间通讯之二】管道Pipe
IPC进程间通信+管道Pipe IPC(Inter-Process Communication.进程间通信). 管道用于进程间共享数据,事实上质是共享内存 ...
- 算法笔记_207:第五届蓝桥杯软件类决赛部分真题(Java语言C组)
目录 1 数字拆分 2 稍大的串 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 数字拆分 正整数可以表示为若干正整数的累加和. 如,对于正整数n=6,可以分划为: 6 5+1 4+2 4+1+ ...
- 手动脱NsPacK壳实战
作者:Fly2015 这里脱壳的程序是吾爱破解培训的作业2,相较于作业1略微要强一点,可是仅仅要掌握了脱壳的ESP定律,脱这个Nspack壳并不难.只是还是蛮有意思的. 1.使用查壳软件对加壳的程序进 ...
- spring mvc json的输入输出
输入 前台代码: var cfg = { type: 'POST', data: JSON.stringify({userName:'winzip',password:'password',mobil ...
- 统计一个文件中出现字符'a'的次数
# -*- coding: utf-8 -*- #python 27 #xiaodeng #统计一个文件中出现字符'a'的次数 #http://www.cnblogs.com/hongten/p/ho ...
- PHP微信公众平台
微信公众平台客户中心微信公众平台开发文档微信公众平台自定义菜单微信公众平台开发(一) 配置接口微信公众平台开发(二) 微信公众平台示例代码分析微信公众平台开发(三) 订阅事件(subscribe)处理 ...
- Xiuno 开发手册正式发布。
下载地址:http://bbs.xiuno.com/down/xiuno.chm.tar.gz
- R语言-查找满足条件的数并获取索引
1.在R语言中,怎样找到满足条件的数呢? 比如给定一个向量c2.要求找到数值大于0的数: > c2 [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.06 0.09 0. ...
- Mac 通过活动监视器关闭卡死进程
前言: 心好累,Lantern太不省事了 之前装过之后,就设定了开启自启动,搞得我上网都受影响(这玩意,qq没事,但是网易云之类的一些软件上网都不行了...就是这玩意搞的鬼) 没办法,点击关闭吧... ...
- Java使用Selenium几个例子
零.姿势 Selenium分为两个版本:Selenium RC和Selenium Webdriver.现在用Selenium Webdriver比较多. Selenium是一套工具,而不仅仅是一个操纵 ...