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. React Native是一套使用 React 构建 Native app 的编程框架

    React Native是一套使用 React 构建 Native app 的编程框架 React Native at first sight what is React Native? 跟据官方的描 ...

  2. 深入解析_Android的自定义布局

    前言: 这篇文章是前Firefox Android工程师(现在跳槽去Facebook了) Lucas Rocha所写,文中对Android中常用的四种自定义布局方案进行了很好地分析,并结合这四种And ...

  3. UI —— 计算器

    #import <UIKit/UIKit.h> @interface MyViewController :UIViewController { NSInteger _firstName; ...

  4. decimal ? 含义

    例如:   decimal ? je = zfje;   意思是  将 JE赋值为  ZFJE ,  并且允许  JE 为 NULL 值 这时JE为引用类型

  5. Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies

    B. Inna and New Matrix of Candies time limit per test 1 second memory limit per test 256 megabytes i ...

  6. android4.0下载问题

    近期在下载android4.0的代码,下列操作 下载Repo $ mkdir ~/bin $ PATH=~/bin:$PATH $ curl https://dl-ssl.google.com/dl/ ...

  7. UVA 11249 - Game(游戏)

    UVA 11249 - Game 题目链接 题意:两堆石头.a和b.每次能取一堆随意数量,或者两堆同一时候取.可是绝对值差不能超过k,最后不能取的人输,问先手能否赢 思路:先如果(a, b)石子,a是 ...

  8. role &#39;PLUSTRACE&#39; does not exist

    I have created a new user named watson and granted the related priviledges as following: SQL> cre ...

  9. 如何获得SQL Server索引使用情况

    原文:如何获得SQL Server索引使用情况 原文出自: http://www.mssqltips.com/sqlservertip/1239/how-to-get-index-usage-info ...

  10. SPOJ 15. The Shortest Path 堆优化Dijsktra

    You are given a list of cities. Each direct connection between two cities has its transportation cos ...