这是一道搜索题,我们很容易得到目标值的上下界,然后就只能枚举了。

就是将x轴上的点排序之后从左到右依次考察每个点,每个点要么在线段的左端点,要么在线段的右端点。

点编号从0到n-1,从编号为1的点开始,在枚举的过程中不断压缩上界,有一种情况需要特别讨论,即哪种一条线段恰好覆盖相邻两个点的。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <ctime>
#pragma comment(linker, "/STACK:102400000,102400000")
#define lson (u << 1)
#define rson (u << 1 | 1)
#define rep(i, a, b) for(i = a; i < b; i++)
#define reps(i, a, b, c) for(i = a; i < b; i += c)
#define repi(i, a, b) for(i = a; i >= b; i--)
#define cls(i, j) memset(i, j, sizeof i)
using namespace std;
typedef __int64 ll;
const double eps = 1e-;
const double pi = acos(-1.0);
const int maxn = 1e5 + ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3fffffffffffffff;
const ll mod = 1e9 + ; double a[];
int n;
double maxi, mini; double dfs(int u, int pre, double limit, int fixed){
//printf("%d %d\n",u, pre);
if(u >= n - ) return limit;
if(limit <= mini) return mini;
double to_left = a[u] - a[pre];
double to_right = a[u + ] - a[u];
double tem;
if(fixed){
if(to_left >= limit) return dfs(u + , u, limit, );
if(to_right >= * limit || to_right == limit) return dfs(u + , u + , limit, );
if(to_right > limit) return dfs(u + , u + , limit, );
if(to_right < limit) return mini;
}
if(to_left >= limit) return dfs(u + , u, limit, );
double tem1 = dfs(u + , u, to_left, );
double tem2 = mini;
if(to_right >= * limit) tem2 = dfs(u + , u + , limit, );
else{
if(to_right <= limit) tem2 = dfs(u + , u + , to_right, );
double tem3 = mini;
if(limit >= to_right / ) tem3 = dfs(u + , u + , to_right / , );
tem2 = max(tem2, tem3);
tem3 = dfs(u + , u + , min(to_right, limit), );
tem3 = max(tem2, tem3);
if(limit < to_right / ) tem3 = dfs(u + , u + , limit, );
tem2 = max(tem2, tem3);
}
return max(tem1, tem2);
} int main(){
// freopen("in.txt", "r", stdin);
int T;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int i;
rep(i, , n) scanf("%lf", &a[i]);
sort(a, a + n);
a[n] = ;
mini = (double)linf;
rep(i, , n) mini = min(mini, a[i] - a[i - ]);
maxi = (double)linf;
rep(i, , n - ) maxi = min(maxi, max(a[i + ] - a[i], a[i] - a[i - ]));
double ans = dfs(, , maxi, );
printf("%.3f\n", ans);
}
return ;
}

hdu4932 Miaomiao's Geometry的更多相关文章

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

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

  2. BestCoder Round #4 之 Miaomiao's Geometry(2014/8/10)

    最后收到邮件说注意小数的问题!此代码并没有过所有数据,请读者参考算法, 自己再去修改一下吧!注意小数问题! Miaomiao's Geometry Time Limit: 2000/1000 MS ( ...

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

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

  4. Miaomiao's Geometry

    HDU 4932  Bestcoder Problem Description There are N point on X-axis . Miaomiao would like to cover t ...

  5. 【HDOJ】4932 Miaomiao's Geometry

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

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

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

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

    HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...

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

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

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

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

随机推荐

  1. PostgreSQL Replication之第十二章 与Postgres-XC一起工作(7)

    12.7 处理故障转移和删除节点 在本节中,我们将看看故障切换如何处理.我们还将看看如何使用安全可靠的方法添加节点到Postgres-XC设置以及如何从Postgres-XC设置删除节点. 12.7. ...

  2. Lintcode: Majority Number II

    Given an array of integers, the majority number is the number that occurs more than 1/3 of the size ...

  3. CSS自定义弹出框

    <script type="text/javascript" language="javascript"> function sAlert(str) ...

  4. poj 1417(并查集+简单dp)

    True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2087   Accepted: 640 Descrip ...

  5. [转]Chrome 控制台console的用法

    Chrome 控制台console的用法 下面我们来看看console里面具体提供了哪些方法可以供我们平时调试时使用. 目前控制台方法和属性有: ["$$", "$x&q ...

  6. 关于C语言链表的学习

    今天讲了一种非传统型的链表.听得不是太好. 到数据结构那一部分的时候.一定要好好听听.

  7. CentOS 5.5 Nginx+JDK+MySQL+Tomcat(jsp)成功安装案例

    在CentOS 5.5中安装Nginx+jdk+mysql+tomcat是非常容易的.只需yum安装环境包和nginx.解压安装jdk和tomcat.配置profile文件.server.xml和ng ...

  8. struts文件上传(单文件)

    第01步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  9. MVC权限管理系统dwpro项目分配按钮没有显示的问题

    问题如下: 修改如下: 或者(原因为这个两个地方名要一致,大小写也要注意): 效果图:

  10. XStream xml转java对象

    1:引入jar qn <dependency> <groupId>xstream</groupId> <artifactId>xstream</a ...