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 ...
随机推荐
- Vxlan简介
1.为什么需要Vxlan 1.什么是VXLAN VXLAN(Virtual eXtensible LAN可扩展虚拟局域网),是一种mac in UDP技术.传统的二层帧被封装到了UDP的报文中,通过U ...
- P1576 最小花费 洛谷
https://www.luogu.org/problem/show?pid=1576 题目背景 题目描述 在n个人中,某些人的银行账号之间可以互相转账.这些人之间转账的手续费各不相同.给定这些人之间 ...
- 前端MVC Vue2学习总结(九)——Vuex状态管理插件
一.概要 1.1.Vuex定义与注意事项 Vuex是为vue.js框架更好的管理状态而设计一个插件.Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的 ...
- 10分钟学会前端工程化(webpack4.0)
一.概要 1.1.前端工程化 随着前端的不断发展与壮大,前端变得越来越复杂,组件化.模块化.工程化.自动化成了前端发展中不可或缺的一部分,具体到前端工程化,面临的问题是如何提高编码->测试-&g ...
- Flux --> Redux --> Redux React 入门 基础实例使用
本文的目的很简单,介绍Redux相关概念用法 及其在React项目中的基本使用 假设你会一些ES6.会一些React.有看过Redux相关的文章,这篇入门小文应该能帮助你理一下相关的知识 一般来说,推 ...
- [转] Python 常用第三方模块 及PIL介绍
原文地址 除了内建的模块外,Python还有大量的第三方模块. 基本上,所有的第三方模块都会在PyPI - the Python Package Index上注册,只要找到对应的模块名字,即可用pip ...
- Adding an Exception Breakpoint - Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 25 bey
用如下的方法可以非常方便停留到具体crash的某行代码 Adding an Exception Breakpoint Add an exception breakpoint to your proje ...
- firefox os 开发模拟器1.4版本号安装开发具体解释
首先在使用firefox os 模拟器的时候必须先下载firefox 浏览器,这个是众多web开发人员必备的工具,下载地址firefox 浏览器 .在最新的官方版本号是1.5版的模拟器,可是如今还不是 ...
- CF 558B(Amr and The Large Array-计数)
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【C#】高级语言特有的单例模式
public class Singleton { private Singleton () { } // 变量标记为 readonly.第一次引用类的成员或创建实例时,仅仅实例化一次instance对 ...