枚举+贪心 HDOJ 4932 Miaomiao's Geometry
/*
题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交
枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则往右边放,
判断一下,取最大值。这题二分的内容少
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
double x[MAXN];
int n; bool check(double len) {
int last = -;
for (int i=; i<=n; ++i) {
if (i == || i == n) continue;
if (last == -) {
if (x[i] - len >= x[i-]) {
last = -; continue;
}
else if (x[i] + len <= x[i+]) {
last = ; continue;
}
else return false;
}
else if (last == ) {
if (x[i-] + len == x[i]) {
last = -; continue;
}
else if (x[i] - len >= x[i-] + len) {
last = -; continue;
}
else if (x[i] + len <= x[i+]) {
last = ; continue;
}
else return false;
}
}
return true;
} int main(void) { //HDOJ 4932 Miaomiao's Geometry
//freopen ("HDOJ_4932.in", "r", stdin); int T; scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
for (int i=; i<=n; ++i) {
scanf ("%lf", &x[i]);
}
sort (x+, x++n); double ans = 0.0;
for (int i=; i<=n; ++i) {
if (check (x[i] - x[i-])) ans = max (ans, x[i] - x[i-]);
if (check ((x[i] - x[i-]) * 0.5)) ans = max (ans, (x[i] - x[i-]) * 0.5);
} printf ("%.3f\n", ans);
} return ;
}
枚举+贪心 HDOJ 4932 Miaomiao's Geometry的更多相关文章
- hdoj 4932 Miaomiao's Geometry 【暴力枚举】
题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...
- 【HDOJ】4932 Miaomiao's Geometry
递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. #include <cstdio> #include <cstring> #incl ...
- hdu 4932 Miaomiao's Geometry(暴力枚举)
pid=4932">Miaomiao's Geometry ...
- HDU 4932 Miaomiao's Geometry(推理)
HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...
- hdu 4932 Miaomiao's Geometry(暴力)
题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- BestCoder Round #4 之 Miaomiao's Geometry(2014/8/10)
最后收到邮件说注意小数的问题!此代码并没有过所有数据,请读者参考算法, 自己再去修改一下吧!注意小数问题! Miaomiao's Geometry Time Limit: 2000/1000 MS ( ...
- 51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
- BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...
随机推荐
- [ 浙江大学 程序设计专题 ] 四个专题代码 报告 PPT共享
[原创]转载请注明出处,请勿用于作弊 专题一: 链接: https://pan.baidu.com/s/11xCwvuPHDkTPeOB_yzJWnw 提取码: prup 专题二: 链接: https ...
- Max Num
Problem Description There are some students in a class, Can you help teacher find the highest studen ...
- SQL SERVER代理作业删除失败问题
在SQL Server 2005上遇到了先删除已运行维护计划后,再删除代理中由其产生的作业时,提示删除失败. DELETE 语句与 REFERENCE 约束"FK_subplan_job ...
- php配置(php7.3)
[PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; PHP's initialization file, general ...
- ssh forwarding 配置
假设有服务器A,属于某一内网,无法直接登录. A: 10.0.1.48 root/password@a 但我们有一台跳板机器可以访问该Server A B: 10.0.2.48 root/passwo ...
- CentOS 7加强安全性:
CentOS 7加强安全性:1. 更改 root 密码************************************************************************* ...
- Samba完整篇 ubuntu 10.04
基本的服务器准备工作 修改Root密码 sudo passwd root 在提示下建立新密码 修改静态IP: sudo gedit /etc/network/interfaces #网络配置文件 ...
- 【转】winform 程序实现一次只能打开一个该程序
ref: http://www.jb51.net/article/17747.htm //在程序的main函数中加入以下代码 bool createdNew; System.Threading.Mut ...
- HDU 5265 pog loves szh II (二分查找)
[题目链接]click here~~ [题目大意]在给定 的数组里选两个数取模p的情况下和最大 [解题思路]: 思路见官方题解吧~~ 弱弱献上代码: Problem : 5265 ( pog love ...
- HTML5超科幻个人主页
在线演示地址:http://me.cpwl.site 备用地址:http://cpwl.sinaapp.com 部分截图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...