hdu4932 Miaomiao's Geometry
这是一道搜索题,我们很容易得到目标值的上下界,然后就只能枚举了。
就是将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的更多相关文章
- 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(2014/8/10)
最后收到邮件说注意小数的问题!此代码并没有过所有数据,请读者参考算法, 自己再去修改一下吧!注意小数问题! Miaomiao's Geometry Time Limit: 2000/1000 MS ( ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- Miaomiao's Geometry
HDU 4932 Bestcoder Problem Description There are N point on X-axis . Miaomiao would like to cover t ...
- 【HDOJ】4932 Miaomiao's Geometry
递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. #include <cstdio> #include <cstring> #incl ...
- BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...
- 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 ...
随机推荐
- 求树的重心(POJ1655)
题意:给出一颗n(n<=2000)个结点的树,删除其中的一个结点,会形成一棵树,或者多棵树,定义删除任意一个结点的平衡度为最大的那棵树的结点个数,问删除哪个结点后,可以让平衡度最小,即求树的重心 ...
- 最近兰州的js风格写个插件和一个template engine
/* *@Product Name: Rational Framework Author: Calos Description: pager !important: pager */ (functio ...
- Python学习笔记总结1:字符串表示str与repr的用法比较
参考博文地址:http://blog.csdn.net/yyt8yyt8/article/details/7030416 值转化为字符串常用以下三种方法: 1. str函数 str函数转化为合理形式的 ...
- [Ubuntu] 转载-使用Ubuntu修复grub
原文地址:http://fav.coketea.com/article_show.php?id=1 步骤一.以试用方式进入ubuntu光盘系统,打开终端(快捷键ctrl+alt+t): 步骤二.获取r ...
- NOIP201105铺地毯
NOIP201105铺地毯 [问题描述]为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有n 张地毯,编号从1 到n.现在将这些地毯按照 ...
- NOIP201208同余方程
NOIP201208同余方程 描述 求关于x的同余方程ax ≡ 1 (mod b)的最小正整数解. 格式 输入格式 输入只有一行,包含两个正整数a, b,用一个空格隔开. 输出格式 输出只有一行,包含 ...
- T-sql语句中GO的作用及语法【转】
1. 作用: 向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号.2. 语法:一批 Transact-SQL 语句GO如Select 1Select 2Select ...
- 使用uiautomatorviewer和uiautomator来做android的UI测试
来自:http://university.utest.com 作者:Angelos Nakulas (All Authored Courses) 译者:Elaine00 目录 简介 什 ...
- 编写更少bug的程序的六条准则
如何编写更少bug的程序? 尽可能避免常见的程序错误. 沟通设计先行 + 编写可复用代码 + 做得更多 + 做的更少 + 创造“编程心流”+ 严格的程序测试 ...
- linux设备驱动归纳总结(三):2.字符型设备的操作open、close、read、write【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59417.html linux设备驱动归纳总结(三):2.字符型设备的操作open.close.rea ...