BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告
题目链接: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) 解题报告的更多相关文章
- BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ...
- BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...
- 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,使得 ...
- BestCoder17 1002.Select(hdu 5101) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...
- BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...
- 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,问是否在每个数 ...
- BestCoder20 1002.lines (hdu 5124) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...
- BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...
- BestCoder15 1002.Instruction(hdu 5083) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...
随机推荐
- 修路 BZOJ 4774
修路 [问题描述] 村子间的小路年久失修,为了保障村子之间的往来,法珞决定带领大家修路.对于边带权的无向图 G = (V, E),请选择一些边,使得1 <= i <= d, i号节点和 n ...
- JVM GC 相关
http://blog.csdn.net/cutesource/article/details/5904501 http://www.cnblogs.com/dingyingsi/p/3760447. ...
- CentOS 7.5 初始网络配置
最近刚装完 CentOS 7.5 系统,由于网络不通,导致无法用 yum 命令下载软件,经过了各种折腾,终于搞定了,这里讲解一下 如何设置初始网络. 本案例环境 VmWare 11.0 , 操作系统 ...
- 设计模式之建造者(Builder)模式
设计模式之建造者(Builder)模式 存在一些情况,比如,一些对象会有一些重要的属性,在这些属性没有恰当的值之前,对象不能作为一个完整的产品使用(如一个电子邮件最起码得有收件人地址):还有一些些情况 ...
- Spring的IoC容器概述
以下内容引用自http://wiki.jikexueyuan.com/project/spring/ioc-containers.html: IoC容器 Spring容器是Spring框架的核心.容器 ...
- android Activity生命周期的例子
package com.example.yanlei.yl2; import android.app.AlertDialog; import android.content.DialogInterfa ...
- QML 开发神奇加成之为网络资源设置本地缓存
QML 开发神奇加成之为网络资源设置本地缓存 直接上码: #include <QNetworkAccessManager> #include <QNetworkDiskCache&g ...
- HDU1800 Flying to the Mars 【贪心】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- leetcode最长递增子序列问题
题目描写叙述: 给定一个数组,删除最少的元素,保证剩下的元素是递增有序的. 分析: 题目的意思是删除最少的元素.保证剩下的元素是递增有序的,事实上换一种方式想,就是寻找最长的递增有序序列.解法有非常多 ...
- BeagleBone Black Industrial 杂谈
前言 原创文章,转载引用务必注明链接.水平有限一己拙见,欢迎指正. 本文使用markdown写成,为获得更好的阅读体验,推荐访问我的博客原文: 初版BeagleBone Black(Rev A4) ...