HDU 4932 贪心
Miaomiao's Geometry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 191 Accepted Submission(s): 38
There are 2 limits:
1.A point is convered if there is a segments T , the point is the left end or the right end of T.
2.The length of the intersection of any two segments equals zero.
For example , point 2 is convered by [2 , 4] and not convered by [1 , 3]. [1 , 2] and [2 , 3] are legal segments , [1 , 2] and [3 , 4] are legal segments , but [1 , 3] and [2 , 4] are not (the length of intersection doesn't equals zero), [1 , 3] and [3 , 4]
are not(not the same length).
Miaomiao wants to maximum the length of segements , please tell her the maximum length of segments.
For your information , the point can't coincidently at the same position.
There is a number T ( T <= 50 ) on the first line which shows the number of test cases.
For each test cases , there is a number N ( 3 <= N <= 50 ) on the first line.
On the second line , there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
3
3
1 2 3
3
1 2 4
4
1 9 100 10
1.000
2.000
8.000HintFor the first sample , a legal answer is [1,2] [2,3] so the length is 1.
For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2.
For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8.
pid=4931" style="color:rgb(26,92,200); text-decoration:none">4931
4930pid=4929" style="color:rgb(26,92,200); text-decoration:none">4929
简直奇妙,比赛的时候900多就21个过的...,自己当时没考虑到一条线段能覆盖两个点的情况,说究竟还是自己太弱了,不够细心,还有就是自己太心急了,刚敲完就交了,导致罚时比較多,今后得慢慢改,注意到答案仅仅能是距离或者距离的一半,依次枚举即可,对每一个点仅仅有两种选择,一种是选点左边的线段,一种是选右边的线段,当能选左边的时候一定要选左边的,否则选右边的,如果左右两边都不能选,那么这个线段肯定长了,如果当前枚举的距离为x,那么选左边的条件是A[j]-A[j-1]-vis[j]>=x||A[j]==A[j-1]+x,右边这样的就是一条线段覆盖两个点的情况,vis[j]是上一个点对如今这个区间的影响.
代码例如以下:
#include <iostream>
#include <map>
#include<algorithm>
#include <stack>
#include <string.h>
#include <queue>
#include<cstdio>
using namespace std;
#define INF 5e9+7
typedef long long LL;
int main()
{
//freopen("in.txt","r",stdin);
long long T,N;
double A[100];
double vis[100];
cin>>T;
while(T--)
{
cin>>N;
for(int i=1; i<=N; i++)cin>>A[i];
sort(A+1,A+N+1);
double ans=0;
A[N+1]=INF;
for(int i=1; i<=N-1; i++)
{
memset(vis,0,sizeof(vis));
double x=A[i+1]-A[i];
bool ok1=true,ok2=true;
for(int j=2; j<=N-1; j++)
{
if((A[j]-A[j-1]-vis[j]>=x)||(A[j]==A[j-1]+x))
{
continue;
}
if(A[j+1]-A[j]>=x)
{
vis[j+1]=x;
continue;
}
ok1=false;
break;
}
if(ok1)
{
ans=max(x,ans);
}
memset(vis,0,sizeof(vis));
for(int j=2; j<=N-1; j++)
{
if(A[j]-A[j-1]-vis[j]>=x/2||A[j]==A[j-1]+x/2)
{
continue;
}
if(A[j+1]-A[j]>=x/2)
{
vis[j+1]=x/2;
continue;
}
ok2=false;
break;
}
if(ok2)ans=max(ans,x/2);
}
printf("%.3f\n",ans);
}
return 0;
}
HDU 4932 贪心的更多相关文章
- 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坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 1735(贪心) 统计字数
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...
- hdu 4974 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- HDU 2307 贪心之活动安排问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1052 贪心+dp
http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...
随机推荐
- UVA 10054 The Necklace
完全就是哭瞎的节奏···QAQ 又是图论··· 题意:有一种项链,每个珠子上有两种颜色,相同颜色的两颗珠子的两头相连,如果能连成环输出珠子的顺序,不能连成环输出"some beads may ...
- delegate 为什么用 weak属性
weak指针主要用于“父-子”关系,父亲拥有一个儿子的strong指针,因此是儿子的所有者:但是为了阻止所有权回环,儿子需要使用weak指针指向父亲:你的viewcontroller通过strong指 ...
- JQuery笔记:JQuery和JavaScript的联系与区别
来源:http://www.ido321.com/1019.html ps:LZ觉得这个标题有点大了,超出了能力范围,不喜勿碰.目前只记录LZ能力范围内的,日后持续补充. 一.JQuery对象和DOM ...
- C++ 之高效使用STL ( STL 算法分类)
http://blog.csdn.net/zhoukuo1981/article/details/3452118
- 《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇:简介及目录》(附上完整工程文件)
跑酷游戏制作 游戏类型: 此游戏Demo,为跑酷类游戏. 框架简介: 游戏通常由程序代码和资源组成.如果说模型.贴图.声音之类的可以给游戏环境提供一个物理描述和设置,那么脚本和代码块会给游戏赋予生命, ...
- Ensemble learning(集成学习)
集成学习:是目前机器学习的一大热门方向,所谓集成学习简单理解就是指采用多个分类器对数据集进行预测,从而提高整体分类器的泛化能力. 我们在前面介绍了.所谓的机器学习就是通过某种学习方法在假设空间中找到一 ...
- 【Hadoop学习】HDFS 短路本地读
Hadoop版本:2.6.0 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4146296.html 背景 ...
- JavaFx版本植物大战僵尸
http://www.cnblogs.com/lslvxy/archive/2013/04/17/3026711.html —————————————————————————————————————— ...
- SpringDataMongoDB介绍(一)-入门
SpringDataMongoDB介绍(一)-入门 本文介绍如何应用SpringDataMongoDB操作实体和数据库,本文只介绍最基本的例子,复杂的例子在后面的文章中介绍. SpringDataMo ...
- Edit Box多行显示时如何使滚动条始终在下方
两种方法: ① CEdit *pEdit = ((CEdit*)GetDlgItem(IDC_EDIT_RXDATA)); pEdit->LineScroll(pEdit->GetLin ...