HDU 4932 Miaomiao's Geometry

pid=4932" target="_blank" style="">题目链接

题意:给定x轴上一些点(不反复),如今要选一个线段,使得能放进这些区间中,保证线段不跨过点(即线段上仅仅能是最左边或最右边是点),而且没有线段相交,求能放进去的最大线段

思路:推理一下,仅仅有两点之间的线段,还有线段的一半可能符合题意。然后对于每种线段,去推断一下能不能成功放进去。这步用贪心。优先放左边,不行再放右边

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; const int N = 55;
const double eps = 1e-9;
int t, n;
double a[N]; bool notless(double a, double b) {
if (fabs(a - b) < eps) return true;
return a > b;
} bool judge(double len) {
int flag = 1;
for (int i = 2; i < n; i++) {
if (flag && notless(a[i] - a[i - 1], len))
continue;
else if (flag && a[i] - a[i - 1] < len && notless(a[i + 1] - a[i], len * 2))
continue;
else if (flag && a[i] - a[i - 1] < len && notless(a[i + 1] - a[i], len)) {
if (fabs(a[i + 1] - a[i] - len) >= eps)
flag = 0;
continue;
}
else if (!flag && notless(a[i + 1] - a[i], len * 2)) {
flag = 1;
continue;
}
else if (!flag && notless(a[i + 1] - a[i], len)) {
if (fabs(a[i + 1] - a[i] - len) < eps)
flag = 1;
continue;
}
return false;
}
return true;
} 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 ans = 0;
for (int i = 1; i < n; i++) {
double len = a[i + 1] - a[i];
if (judge(len))
ans = max(ans, len);
len /= 2;
if (judge(len))
ans = max(ans, len);
}
printf("%.3lf\n", ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 4932 Miaomiao&#39;s Geometry(推理)的更多相关文章

  1. hdu 4932 Miaomiao&#39;s Geometry(暴力)

    题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...

  2. hdu 4932 Miaomiao&#39;s Geometry(暴力枚举)

    pid=4932">Miaomiao's Geometry                                                               ...

  3. hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】

    题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...

  4. hdu4932 Miaomiao&#39;s Geometry (BestCoder Round #4 枚举)

    题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...

  5. BestCoder Round #4 Miaomiao&#39;s Geometry (暴力)

    Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...

  6. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

  7. BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...

  8. 【HDOJ】4932 Miaomiao's Geometry

    递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. #include <cstdio> #include <cstring> #incl ...

  9. HDU 4932 贪心

    Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

随机推荐

  1. 实现能够直接粘QQ贴截图的bug管理功能

    对于一个功能强大的协作平台来说,todo管理和bug管理是不可缺少的功能.Todo和bug往往不是通过一些简单的文字就能实现的,有时候须要配以图片的说名,之前用过的项目管理平台都是以附件的形式上传图片 ...

  2. HDU-2857-Mirror and Light(计算几何)

    Problem Description The light travels in a straight line and always goes in the minimal path between ...

  3. 如何解决vector 析构函数的异常 opencv Assert _CrtIsValidHeapPointer

    一气呵成代码,但是,当发生执行_CrtIsValidHeapPointer例外,去搭调了一上午Bug.最终获得 跟踪定位到 _CrtIsValidHeapPointer ,注意到 g 8h&quo ...

  4. javascript 比量str今天的日期是,参数diff

    function isToday(str) { var d = new Date(str.replace(/-/g, "/")); var todaysDate = new Dat ...

  5. C该结构变化 struct typedef

     这几天看代码,看到若干类型的结构,例如下列结构声明: struct    book{ string name; int price; int num; }; 此种结构定义结构变量的格式例如以下: ...

  6. 跨域 Iframe 通信解决方案(兼容 IE 系列浏览器。)

    实现思路: 1.postMessage(IE8+, Firefox 3.1+, Opera 9+, Safari, and Chrome) 2.利用window.navigator共享信息,使支持IE ...

  7. RH253读书笔记(8)-Lab 8 Securing Data

    Lab 8 Securing Data Goal: Gain familiarity with encryption utilities Sequence 1: Using SSH keys with ...

  8. Hadoop 2.6.0分布式部署參考手冊

    Hadoop 2.6.0分布式部署參考手冊 关于本參考手冊的word文档.能够到例如以下地址下载:http://download.csdn.net/detail/u012875880/8291493 ...

  9. 库函数atoi()的实现

    int atoi(const char *nptr); 假设第一个非空格字符存在,是数字或者正负号则開始做类型转换,之后检測到非数字(包含结束符 \0) 字符时停止转换.返回整形数. 否则,返回零. ...

  10. 安装Docker

    安装Docker 1. 增加Repository配置文件 cat >/etc/yum.repos.d/docker.repo <<-EOF [dockerrepo]name=Dock ...