题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932

题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点。这个最长线段需要满足两个条件:(1)每个点是某条线段的左端点或右端点   (2)任意两条线段之间的重叠部分的长度为0。(一个点重叠默认长度为0,即[1,2] , [2, 3] 视为合法)。还有一点我来补充吧,就是这个最大长度是固定的,看第3组测试数据  1 9 100 10,[-7,1] , [1,9] , [10,18] , [100,108]   长度都为8,不能参差不齐啦~~~~

昨天的BestCoder 4 的 B 题,好多人过pretest,但最终能过final ,寥寥无几啊(当中这行列有我啦),希望过后的失望啊.......天真的做法:每个点求出它两边的间隙,保存较大的那个(因为正常情况下都应该向大的那边扩展啦),然后在所有点的较大的那个中找出最小的那个就是答案了......

const int maxn =  + ;
int maxx[maxn], minn[maxn];
int a[maxn]; int main()
{
int T, n;
while (scanf("%d", &T) != EOF)
{
while (T--)
{
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
sort(a, a+n);
int ll = abs(a[]-1e9);
maxx[] = max(a[]-a[], ll);
for (int i = ; i < n-; i++)
maxx[i] = max(a[i]-a[i-], a[i+]-a[i]);
int rr = abs(1e9-a[n-]);
maxx[n-] = max(a[n-]-a[n-], rr);
double ans = 1e9;
for (int i = ; i < n; i++)
ans = min((double)maxx[i], ans);
printf("%.3f\n", ans);
}
}
return ;
}

貌似挺多人好像我这样做滴= =。

给组测试数据立马知道出事了!!!!

6

-1     0    10     12    18    20

答案:   3

错误答案:6

如果忽略每两个点之间的间隙/2 而不去逐个测试,也就是只测试 每两个点之间的间隙,那么就  呵呵  了,会得出 2 这个答案,也是错滴!!! 可以这样想,对于相邻的两个点,它们可以面向对方扩展的嘛,也不一定都要背对着扩展的。

还有一个坑爹的地方,误差!!!一开始对于输出 a real number 就觉得好似是多余的,原来暗示着要测试误差呢。

总的来说,BestCoder 的题目:潜水淹死人!!!

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; #define eps 1e-9
#define pb push_back
const int maxn = + ;
vector<double> vd;
double a[maxn];
int n; bool check(double gap)
{
double pre = a[];
for (int i = ; i < n; i++)
{
if (fabs(a[i]-pre) < eps) // 没这句会wa
continue;
if (pre > a[i])
return false;
else if (pre + gap <= a[i])
pre = a[i];
else
pre = a[i] + gap; // 这一句意味深长啊,如果它更新后比下一个待检测的a[i]大,即: if (pre > a[i]) 就没有继续比较下去的必要
}
return true;
} int main()
{
int T;
while (scanf("%d", &T) != EOF)
{
while (T--)
{
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%lf", &a[i]);
sort(a, a+n);
for (int i = ; i < n; i++)
{
vd.pb(a[i]-a[i-]);
vd.pb((a[i]-a[i-])/); // 别遗漏
}
double ans = ;
for (int i = vd.size(); i >= ; i--)
{
if (check(vd[i]))
ans = max(ans, vd[i]);
}
printf("%.3f\n", ans);
}
}
return ;
}

姑且归去数学专区吧= =

BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告的更多相关文章

  1. BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ...

  2. BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...

  3. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  4. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  5. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  6. BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...

  7. BestCoder20 1002.lines (hdu 5124) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...

  8. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

  9. BestCoder15 1002.Instruction(hdu 5083) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...

随机推荐

  1. linux 管道符号 | ,以及&& ||等等特殊符号笔记

    管道和重导向:“|”.“>”.“>>”.“<” 重导向就是使命令改变它所认定的标准输出.“>”可将结果输出到文件中,该文件原有内容会被删除,“>>”则将结果附 ...

  2. MySQL 中 key, primary key ,unique key,index的区别

    一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id int(11) NOT NULL auto_increment, user_n ...

  3. CSS 居中 可随着浏览器变大变小而居中

    关键代码: 外部DIV使用: text-align:center; 内部DIV使用: margin-left:auto;margin-right:auto 例: <div style=" ...

  4. Vue.js组件的通信之子组件向父组件的通信

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 基于centos 创建一个stress镜像

    最近需要学习docker的Cgroups机制,需要用到stress进行测试,前期工作就是自己创建一个stress镜像. 新建一个 Dockerfile 文件 [vagrant@localhost ~] ...

  6. 33.JAVA编程思想——JAVA IO File类

    33.JAVA编程思想--JAVA IO File类 RandomAccessFile用于包括了已知长度记录的文件.以便我们能用 seek()从一条记录移至还有一条:然后读取或改动那些记录. 各记录的 ...

  7. Swift的可选链,类型转换和扩展

    可选链(Optional Chaining) 可选链是一种请求或调用属性.方法,子脚本的过程. 可选性体现于请求或调用的目标当前可能为nil.若不为nil则成功调用.否则返回nil并将链失效. 调用可 ...

  8. SQL ORDER BY 关键字

    SQL ORDER BY 关键字 ORDER BY 关键字用于对结果集进行排序. SQL ORDER BY 关键字 ORDER BY 关键字用于对结果集按照一个列或者多个列进行排序. ORDER BY ...

  9. 用rsync命令删除大文件夹

    删除大文件夹 rsync 命令做同步文件用的命令 我们可以借助其快速的运行 来对大文件夹删除:原来就是 新建一个空文件夹 然后把这个空文件夹同步到一个大文件夹下面: 这样会删除大文件夹下面的内容 是高 ...

  10. binary-tree-postorder-traversal——二叉树后续遍历

    Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...