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 ...
随机推荐
- [转] 使用C#开发ActiveX控件
双魂人生 原文 使用C#开发ActiveX控件 ActiveX 是一个开放的集成平台,为开发人员.用户和 Web生产商提供了一个快速而简便的在 Internet 和 Intranet 创建程序集成和内 ...
- [Everyday Mathematics]20150128
求极限 $$\bex \lim_{x\to 0}\sex{\frac{e^x+e^{2x}+\cdots+e^{nx}}{n}}^\frac{1}{x}. \eex$$
- 使用SQL语句清空数据库所有表的数据
使用SQL语句清空数据库所有表的数据 近来发现数据库过大,空间不足,因此打算将数据库的数据进行全面的清理,但表非常多,一张一张的清空,实在麻烦,因此就想利用SQL语句一次清空所有数据.找到了三种方法进 ...
- IOS 屏幕截图 UIScrollview
//截图UIView:截全图 -(UIImage*)captureView:(UIView *)theView{ CGRect rect = theView.frame; if ([theView i ...
- 微信多媒体上传图片,创建卡券上传 LOGO
//*****************************************多媒体上传图片 begin******************************************** ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_selected_list_value(self, locator)
def get_selected_list_value(self, locator): """Returns the value of the selected elem ...
- Mac vim iterm2配色方案
转自:http://www.vpsee.com/2013/09/use-the-solarized-color-theme-on-mac-os-x-terminal/ 相信长期浸泡在终端和代码的小伙伴 ...
- JVM基础知识(1)-JVM内存区域与内存溢出
JVM基础知识(1)-JVM内存区域与内存溢出 0. 目录 什么是JVM 运行时数据区域 HotSpot虚拟机对象探秘 OutOfMemoryError异常 1. 什么是JVM 1.1. 什么是JVM ...
- uniPanel特效
function beforeInit(sender){ sender.layout='accordion'; Ext.apply (sender, {title:'供应链',style:'text- ...
- TQ210裸机编程(4)——按键(中断法)
S5PV210有4个向量中断控制器(VIC),每个向量中断控制器包含32个中断源. 当某个中断源产生中断时,CPU会自动的将VICxVECTADDRy(x=0,1,2,3,y=0-31)寄存器的值赋给 ...