cf492B Vanya and Lanterns
B. Vanya and Lanterns
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?
The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.
The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.
7 1515 5 3 7 9 14 0
2.5000000000
2 52 5
2.0000000000
Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment[3, 5]. Thus, the whole street will be lit.
题意是给定x轴上n个点的x坐标,每个点可以覆盖[x-d,x+d]的区间,要求在保证覆盖[0,l]的情况下d最小
其实还是模拟……排个序就完了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,l,ans;
double s;
int a[100010];
int main()
{
n=read();l=read();
for (int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+n+1);
for (int i=1;i<n;i++)
{
ans=max(ans,a[i+1]-a[i]);
}
s=ans/2.0;
if (a[1]+0.0>s)s=a[1]+0.0;
if (l-a[n]+0.0>s)s=l-a[n]+0.0;
printf("%.10lf",s);
}
cf492B Vanya and Lanterns的更多相关文章
- Codeforces 492B B. Vanya and Lanterns
Codeforces 492B B. Vanya and Lanterns 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- Vanya and Lanterns
Description Vanya walks late at night along a straight street of length l, lit by n lanterns. Consid ...
- codeforces 492B. Vanya and Lanterns 解题报告
题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...
- Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces Round #280 (Div.2)
A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...
- Codeforces Round #280 (Div. 2) A , B , C
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- [codeforces] 暑期训练之打卡题(一)
每个标题都做了题目原网址的超链接 Day1<Vanya and Lanterns> 题意: 一条长度为 l 的街道,在这条街道上放置了n个相同的灯,街道一端位置记为0,每个灯的位置在ai处 ...
- Lanterns
Lanterns 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/B 题目: Description ...
- codeforces C. Vanya and Scales
C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...
随机推荐
- java中的“包”与C#中的“命名空间
原文地址:http://www.cnblogs.com/lidabo/archive/2012/12/15/2819865.html Package vs. Namespace 我们知道,重用性(re ...
- 轻量级mvvm Web开发框架 postby:http://zhutty.cnblogs.com
今天特别郁闷,怎么说呢,之前一直就用angular,然后这两天用的是avalon这东西,反正,一开始没时间去玩它,第一个任务就是封装个jq插件,实现一个小功能.反正呢,就是越写越郁闷.用过angula ...
- 【winform程序】自定义webrowser控件调用IE的版本
修改注册表: bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROW ...
- Android Game
收起相关游戏 cytus 机械迷城 小小炼狱 deemo 神庙逃离 现代战争4零点行动 植物大战僵尸2中文版 时空幻境 无尽之剑3 超级救火队 迷你冲撞 大战僵尸鸟 侍魂2 flappy bird 混 ...
- jquery之营销系统
// //////////////////////////优惠券开始//////////////////////////// // 给附加条件选择框添加事件 function inputFuJia() ...
- (转)C#中的委托,匿名方法和Lambda表达式
简介 在.NET中,委托,匿名方法和Lambda表达式很容易发生混淆.我想下面的代码能证实这点.下面哪一个First会被编译?哪一个会返回我们需要的结果?即Customer.ID=5.答案是6个Fir ...
- (转)ASP.NET版本的Kindeditor插件的使用(同步)
昨天老大让我自己下载一个kindeditor说要放到“描述”功能中,并且不能提交(一边在textarea中写一边在label控件中将数据显示出来),由于从来没弄过,实在费了一翻劲.所以将此记录下来,一 ...
- MongoDB-C# Driver账户密码登录问题
MongoDb在3.0之后添加了SCRAM-SHA-1,用户验证模式.添加的用户,默认登录协议也是这个. 在登陆的时候就要选择使用这种方式登录.有的gui客户端的登录验证方式还是MONGODB-CR. ...
- 一些小trick~
做质因子分解的时候将先打素数表会节省很多时间
- JQ点击列表显示隐藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...