题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932

Miaomiao's Geometry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 410    Accepted Submission(s): 147
Problem Description
There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length.

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.

Input
There are several test cases.
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.
Output
For each test cases , output a real number shows the answser. Please output three digit after the decimal point.
Sample Input
3 3 1 2 3 3 1 2 4 4 1 9 100 10
Sample Output
1.000 2.000 8.000

Hint

For 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.

Source
BestCoder Round #4

题意:

求最大可以覆盖全部所给的点的区间长度(所给的点必须处于区间两端)。

思路:

答案一定是相邻点之间的差值或者是相邻点之间的差值除以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;//仅仅能向右}elsereturn false;}elsef[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#39;s Geometry (BestCoder Round #4 枚举)相关推荐

  1. HDU 4932 Miaomiao#39;s Geometry(推理)

    HDU 4932 Miaomiao's Geometry 题目链接 题意:给定x轴上一些点(不反复),如今要选一个线段,使得能放进这些区间中,保证线段不跨过点(即线段上仅仅能是最左边或最右边是点),而 ...

  2. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...

  3. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...

  5. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio&g ...

  6. hdu4585 amp; BestCoder Round #1 项目管理(vector应用)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others)    M ...

  7. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    ...

  8. BestCoder Round #90 Kblack loves flag

     BestCoder Round #90 Kblack loves flag 问题描述 kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,kblack得到了一个n∗mn*mn∗ ...

  9. HDU 5804 BestCoder Round #86 Price List (水题)

    Price List 题目链接: 点我打开链接 Source BestCoder Round #86  题意:有一个人去 n 间商店购物,在每家商店购买最多一件物品,也可以什么都不买.给你每家商店的物 ...

最新文章

  1. linux gcc 内联汇编入门
  2. python基础知识资料-Python基础知识(一)—简介
  3. 读经典——《CLR via C#》(Jeffrey Richter著) 笔记_基元类型(三)
  4. win10+Tensorflow2 + cuda +RTX 3080 +cudnn 安装
  5. Eddy的难题_JAVA
  6. 谈谈InnoDB下的记录锁,间隙锁,next-key锁
  7. 中国电子学会scratch等级考试四级
  8. HTML5的LocalStorage和sessionStorage的使用 -缓存
  9. python画roc曲线_使用Python画ROC曲线以及AUC值
  10. 简洁的架构还能高效和准确?清华华为提出新型残差循环超分模型:RRN!
  11. C#泛型委托Predicate、Action、Func
  12. Open3d之点云上色
  13. 只需 1 分钟,这个网站用 AI 分离歌曲的人声、伴奏和乐器声
  14. Excel批量自动填充行号
  15. 描述性物理海洋学 --第五章学习笔记(大洋中水、盐和热收支以及风应力)
  16. linux下ps ef命令详解,linux中ps -ef命令
  17. 靶机渗透练习55-digitalworld.local:MERCY v2
  18. 复试21天Day 21
  19. JAVA-Servlet项目接入支付宝网站支付
  20. c语言在打开文件时会使用到的函数,C语言打开文件操作

热门文章

  1. c++语言自定义操作符,C++语言复习笔记二
  2. c语言扫描图片的坐标,tc 如何在指定坐标处 输出bmp图片??
  3. 调试记录- error: #error “must enable c++17“
  4. 计算机hub体系部件,原来如此!USB Hub接口为啥都是4个7个或10个?
  5. 【题解】p1230 智力大冲浪
  6. JavaEE课程目标、个人目标、互联网应用和企业级应用的区别
  7. iOS9 判断微信qq是否安装
  8. 手把手教你做关键词匹配项目(搜索引擎)---- 第六天
  9. Symbian学习笔记(4)——在GUI应用中使用图像
  10. ACM组队训练记录(Grooming)