HDU 4932 Miaomiao's Geometry(推理)
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's Geometry(推理)的更多相关文章
- 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 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...
- hdu4932 Miaomiao's Geometry (BestCoder Round #4 枚举)
题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...
- 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 ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...
- 【HDOJ】4932 Miaomiao's Geometry
递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. #include <cstdio> #include <cstring> #incl ...
- HDU 4932 贪心
Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- laydate天蓝色的皮肤
要使用该网站日期控件.就到网上找laydate,但laydate无天蓝色的肌肤,其他皮肤不能进行集成和现场,对自己做了一个天蓝色的肌肤,分享给大家使用. 皮肤下载 版权声明:本文博主原创文章.博客,未 ...
- CareerCup它1.8 串移包括问题
[称号] 原文: 1.8 Assume you have a method isSubstring which checks if one word is a substring of another ...
- window.history.back()的改进方法window.history.go()
今天在做项目时,測试人员提出了一条bug,起初没当回事,在改动过程中才意识到其重要性,故记录下来. 依照需求,系统应该实现例如以下的功能:有三个关联的页面a.aspx(简称a),b.aspx(简称b) ...
- [Ruby]How to create singleton class ?
Singleton is one design pattern in the software engineering. Ruby has its own special feature to dec ...
- HDOJ 5188 zhx and contest 贪婪+01背包
zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- FileZilla 错误425 Can't open data connection 读取目录列表失败
新装FileZilla FTP Server,设置好后,客户端能连接,但是出Error:[读取目录列表失败]:同时,服务端出Error:[425 Can't open data connection] ...
- 第七章——DMVs和DMFs(2)——用DMV和DMF监控索引性能
原文:第七章--DMVs和DMFs(2)--用DMV和DMF监控索引性能 本文继续介绍使用DMO来监控,这次讲述的是监控索引性能.索引是提高查询性能的关键性手段.即使你的表上有合适的索引,你也要时时刻 ...
- RH133读书笔记(11)-Lab 11 System Rescue and Troubleshooting
Lab 11 System Rescue and Troubleshooting Goal: To build skills in system rescue procedures. Estimate ...
- java 工厂的变形模拟的各种应用
工厂模式是在项目开发中使用效率高,意一个接口,该定义用于创建对象.让子类来决定哪一个类实例. 这就是一个工厂类的示意图 接着来一个简单的样例: 如上图所看到的,我们首先定义我们的产品抽象类接口,也能够 ...
- SQL Server 2008性能故障排查(三)——I/O
原文:SQL Server 2008性能故障排查(三)--I/O 接着上一章:CPU瓶颈 I/O瓶颈(I/O Bottlenecks): SQLServer的性能严重依赖I/O子系统.除非你的数据库完 ...