hdu4932 Miaomiao's Geometry (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.
题意:
求最大可以覆盖全部所给的点的区间长度(所给的点必须处于区间两端)。
思路:
答案一定是相邻点之间的差值或者是相邻点之间的差值除以2,那么把这些可能的答案先算出来。然后依次从最大的開始枚举进行验证就可以。
代码例如以下:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 147;
int f[MAXN];//记录线段方向
double p[MAXN];
double d[MAXN];//相邻断点的差值
int n;
void init()
{
memset(p,0,sizeof(p));
memset(f,0,sizeof(f));
memset(d,0,sizeof(d));
} bool Judge(double tt)
{
int i;
for(i = 1; i < n-1; i++)
{
if(p[i] - tt < p[i-1] && p[i] + tt > p[i+1])
break;//不管向左还是向右均为不符合
if(p[i] - tt >= p[i-1])//向左察看
{
if(f[i-1] == 2)//假设前一个是向右的
{
if(p[i] - p[i-1] == tt)
f[i] = 1;//两个点作为线段的两个端点
else if(p[i] - p[i-1] >= 2*tt)//一个向左一个向右
{
f[i] = 1;
}
else if(p[i] + tt <= p[i+1])
{
f[i] = 2;//仅仅能向右
}
else
return false;
}
else
f[i] = 1;
}
else if(p[i] + tt <= p[i+1])
f[i] = 2;
}
if(i == n-1)//所有符合
return true;
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%lf",&p[i]);
}
sort(p,p+n);
int cont = 0;
for(int i = 1; i < n; i++)
{
d[cont++] = p[i] - p[i-1];
d[cont++] = (p[i] - p[i-1])/2.0;
}
sort(d,d+cont);
double ans = 0;
for(int i = cont-1; i >= 0; i--)
{
memset(f,0,sizeof(f));
f[0] = 1; //開始肯定是让线段向左
if(Judge(d[i]))
{
ans = d[i];
break;
}
}
printf("%.3lf\n",ans);
}
return 0;
}
hdu4932 Miaomiao's Geometry (BestCoder Round #4 枚举)的更多相关文章
- 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 4932 Miaomiao's Geometry(推理)
HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...
- hdu 4932 Miaomiao's Geometry(暴力)
题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...
- hdu 4932 Miaomiao's Geometry(暴力枚举)
pid=4932">Miaomiao's Geometry ...
- hdoj 4932 Miaomiao's Geometry 【暴力枚举】
题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- BestCoder Round #89 02单调队列优化dp
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01 HDU 5944 水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
随机推荐
- 关于史考特证券(scottrade Inc)资金转出的手续费问题
投资美股账户的朋友可能开始的时候并没有关心史考特账户转出的费用,其实,仔细算一下这个费用还是蛮贵的,根据官网的文档可以明确知道,转出史考特账户资金到国内银行的费用由以下几项组成: 1. 国际电汇资金费 ...
- 【APP问题定位(三)】adb安装
先来剧透一下我们需要使用的工具 bin包 一个安装目录,可以免安装直接调用adb命令 Android SDK platform tools 下面依次为大家介绍,第1个和第2 ...
- 应用在安卓和ios端APP的证件识别
移动端证件识别智能图文处理,是利用OCR识别技术,通过手机拍摄身份证图像或者从手机相册中加载证件图像,过滤身份证的背景底纹干扰,自动分析证件各文字进行字符切分.识别,最后将识别结果按姓名.地址.民族. ...
- 清理win10过期补丁的命令
作用是删除已经被新版本取代的旧系统文件 DISM.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase 注1: 执行后, 补丁就无法 ...
- 约瑟夫环C#解决方法
/*约瑟夫环 (问题描述) 约瑟夫问题的一种描述是:编号为1,2,......n,的n个人按顺时针方向围坐一圈,每个人持有一个密码(正整数).一开始任意选 一个正整数作为报数的上限值m,从第一个人开始 ...
- 最近ssh遇到异常及解决
1.SSH框架,spring和struts整合,action中注入service不成功,检测是否缺少 struts2-spring-plugin-2.3.4.1.jar包 2.字符串转 json 加了 ...
- C#进阶--WebApi异常处理机制
其实对于C#异常处理大家都不陌生,但是对于在WeiApi上的异常处理实际上也和传统异常处理区别不大,但是却经过封装可以让异常更加友好,https://docs.microsoft.com/en-us/ ...
- 使用.net core在Ubuntu构建一个TCP服务器
介绍和背景 TCP编程是网络编程领域最有趣的部分之一.在Ubuntu环境中,我喜欢使用.NET Core进行TCP编程,并使用本机Ubuntu脚本与TCP服务器进行通信.以前,我在.NET框架本身写了 ...
- tensorflow 从入门到上天教程一
tensorflow 是一个google开源的深度学习的框架,执行性能良好,值得使用. caffe,caffe2 通过配置就可以拼凑一个深度学习框架,大大简化流程但也依赖大量的开源库,性能也不错.20 ...
- TensorFlow学习笔记(一):数据操作指南
扩充 TensorFlow tf.tile 对数据进行扩充操作 import tensorflow as tf temp = tf.tile([1,2,3],[2]) temp2 = tf.tile( ...