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 = 100 + 10; 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 = 0; i < n; i++)scanf("%d", &a[i]);sort(a, a+n);int ll = abs(a[0]-1e9);maxx[0] = max(a[1]-a[0], ll);for (int i = 1; i < n-1; i++)maxx[i] = max(a[i]-a[i-1], a[i+1]-a[i]);int rr = abs(1e9-a[n-1]);maxx[n-1] = max(a[n-1]-a[n-2], rr);double ans = 1e9;for (int i = 0; i < n; i++)ans = min((double)maxx[i], ans);printf("%.3f\n", ans);}}return 0; }
貌似挺多人好像我这样做滴= =。
给组测试数据立马知道出事了!!!!
6
-1 0 10 12 18 20
答案: 3
错误答案:6
如果忽略每两个点之间的间隙/2 而不去逐个测试,也就是只测试 每两个点之间的间隙,那么就 呵呵 了,会得出 2 这个答案,也是错滴!!! 可以这样想,对于相邻的两个点,它们可以面向对方扩展的嘛,也不一定都要背对着扩展的。
还有一个坑爹的地方,误差!!!一开始对于输出 a real number 就觉得好似是多余的,原来暗示着要测试误差呢。
总的来说,BestCoder 的题目:潜水淹死人!!!
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <cmath> 7 #include <vector> 8 using namespace std; 9 10 #define eps 1e-9 11 #define pb push_back 12 const int maxn = 50 + 5; 13 vector<double> vd; 14 double a[maxn]; 15 int n; 16 17 bool check(double gap) 18 { 19 double pre = a[0]; 20 for (int i = 1; i < n; i++) 21 { 22 if (fabs(a[i]-pre) < eps) // 没这句会wa 23 continue; 24 if (pre > a[i]) 25 return false; 26 else if (pre + gap <= a[i]) 27 pre = a[i]; 28 else 29 pre = a[i] + gap; // 这一句意味深长啊,如果它更新后比下一个待检测的a[i]大,即: if (pre > a[i]) 就没有继续比较下去的必要 30 } 31 return true; 32 } 33 34 int main() 35 { 36 int T; 37 while (scanf("%d", &T) != EOF) 38 { 39 while (T--) 40 { 41 scanf("%d", &n); 42 for (int i = 0; i < n; i++) 43 scanf("%lf", &a[i]); 44 sort(a, a+n); 45 for (int i = 1; i < n; i++) 46 { 47 vd.pb(a[i]-a[i-1]); 48 vd.pb((a[i]-a[i-1])/2); // 别遗漏 49 } 50 double ans = 0; 51 for (int i = vd.size(); i >= 0; i--) 52 { 53 if (check(vd[i])) 54 ans = max(ans, vd[i]); 55 } 56 printf("%.3f\n", ans); 57 } 58 } 59 return 0; 60 }
姑且归去数学专区吧= =
转载于:https://www.cnblogs.com/windysai/p/3905740.html
BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告相关推荐
- hdu 2058 解题报告 - The sum problem
hdu 2058 解题报告 - The sum problem 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2058 等差求和公式: Sn=(a1+aN ...
- LETTers比赛第三场 --1002 Ignatius and the Princess III解题报告
提交人:侯建鹏 提交日期:2012/4/16 1002 Ignatius and the Princess III 解题思路(一):动态规划 先设置int p[N][N]; Dp 方程为:p[i][j ...
- 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 ...
- BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...
- HDU 1506 解题报告 Largest Rectangle in a Histogram (单调栈)
看题传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题意比较明显,就是找以某一个矩形为高的最大的矩形.这个题可以用单调栈来求解,需要注意的是如果从 ...
- Fibonacci Tree HDU - 4786——解题报告
立志用更少的代码做更高效的表达 Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do some ...
- hdu 1754 解题报告 I Hate It
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1870解题报告(愚人节的礼物)
愚人节的礼物 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java class ...
最新文章
- oracle中间件微信公众号,对TP5.1中间件融合微信公众号代码的优化
- 汇编语言典型例子详解_数据分析常用的7大思维方法详解
- excel概率密度函数公式_Excel统计函数“F”系列,日常办公数据分析必备7大公式!...
- 西安活动 | 2019年1月13号 拥抱开源, 又见.NET 线下交流活动报名进行中
- A Simple Note on P4FPGA: A Rapid Prototyping Framework for P4
- 软件开发工程师证书有用吗_bim工程师证书有用吗
- 实现OO的最后一公里
- 有没有计算机用户号,刚做的系统怎么有账户-用户帐号系统设计的原则有哪些?...
- python流水灯程序_单片机流水灯汇编语言源代码大全(六款流水灯汇编语言源代码)...
- Java数据持久层框架
- chm格式怎么打开?
- FAN 人脸对齐网络结构详细解析
- 22 mysql有那些”饮鸩止渴”提高性能的方法?
- 影视后期算不算计算机类专业,影视后期是什么意思(后期剪辑属于什么专业)...
- matlab 直接馈通,s函数直接馈通
- 第四天:关看门狗、设置栈、控制icache、重定位、链接脚本
- DSP 中的基础算法和模型的详细解析
- 在SecureCRT使用sz与rz命令上传、下载文件命令介绍
- <table>表格标签属性
- 好用的多国语言翻译软件—“Mate Translate”
热门文章
- Oracle11g客户端安装配置
- 如何更改html广告,js 动态改变广告代码DIV的位置_原生JS通过innerHTML改变div位置...
- go语言实现zip压缩与解压
- 关于升级Vmware ESXI6.7 主机挂在ISCSI共享存储的方法
- MBTI性格类型测试
- 50道编程小题目之【兔子数量】
- Java @override报错的解决方法
- Sublime text 3 SVN插件及使用方法
- 编译 linux 0.01
- 支持IPsec / L2TP / EtherIP测试版下载