Codeforces 492B B. Vanya and Lanterns
Codeforces 492B B. Vanya and Lanterns
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/B
题目:
Description
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?
Input
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.
Output
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.
Sample Input
7 15 15 5 3 7 9 14 0
2.5000000000
2 5 2 5
2.0000000000
Sample Output
Hint
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.
题意:
N盏灯照亮长度为L的街道,使整条街全部被照亮。求灯的最少照亮半径。
分析:
1.将灯的位置排序,先求出相邻两盏灯之间的最大距离,最大距离是每盏灯所照的最大半径的两倍
2.再求第一盏灯到街首的距离和街尾到最后一盏灯的距离
3.比较三个距离的长度,最大值即为所求
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
;
int a[maxn];
int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
int n,l;
scanf("%d%d",&n,&l);
;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+,a+n+); //将灯的位置从小到大排序
a[]=; //街首
a[n+]=l; //街尾
;
]-a[],xx=a[n+]-a[n]; //首尾两盏灯到街首和街尾的距离
;j<n;j++) //两盏灯之间的最大距离
{
a[j]=a[j+]-a[j];
if(a[j]>m)
m=a[j];
}
m=max(*b,max(m,*xx)); //求灯照射的最大直径
double ans=m/2.0;
printf("%.10lf\n",ans);
;
}
昨天写题目的时候没有写max函数,提交后WA了,所以这次看完题目知道要比较大小,就先写了一个max函数。
Codeforces 492B B. Vanya and Lanterns的更多相关文章
- cf492B Vanya and Lanterns
B. Vanya and Lanterns time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 492B. Vanya and Lanterns 解题报告
题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...
- codeforces 677C C. Vanya and Label(组合数学+快速幂)
题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 492B
Description Vanya walks late at night along a straight street of length l, lit by n lanterns. Consid ...
- Vanya and Lanterns
Description Vanya walks late at night along a straight street of length l, lit by n lanterns. Consid ...
- 【39.29%】【codeforces 552E】Vanya and Brackets
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【25.33%】【codeforces 552D】Vanya and Triangles
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【30.23%】【codeforces 552C】Vanya and Scales
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【33.33%】【codeforces 552B】Vanya and Books
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- halcon与C#混合编程
halcon源程序: dev_open_window(0, 0, 512, 512, 'black', WindowHandle)read_image (Image, 'C:/Users/BadGuy ...
- Gulp 之二
Gulp学习2 之前已经配置过一篇啦, 只不过那次是针对browserify 搬运 http://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97%A8 ...
- Android 流媒体系列(一)
Android 设置铃声分析 代码其实没有几行,这里简单记录下学习的过程. Android系统启动时会扫描系统与SD卡中的对媒体文件,分别存入数据库sqlite中,以contentProvider ...
- oracle execute immediate
declare aa ,); l_cnt ); i_yr ; i_curCode ) :='001'; i_vDate date := ...
- SGU 201 Non Absorbing DFA (DP)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出一个自动机,给出所有的转移,其中还有一个 ...
- python 内部函数,以及lambda,filter,map等内置函数
#!/usr/bin/python #encoding=utf-8 def back(): return 1,2, "xxx" #python 可变参数 def test(*par ...
- linux下emacs安装
1.下载地址:http://ftp.gnu.org/pub/gnu/emacs/ 下载文件:emacs-24.2.tar.gz 步骤: 一.安装依赖文件: (先进入root:终端中输入 su -) ...
- Gridview编辑时Jquery自动计算自定义列(鼠标离开输入框Jquery计算)
Jquery片段: <script type="text/javascript"> function compute(nbBoxQuantity, lblQuantit ...
- 在unity中用鼠标实现在场景中拖动物体,用鼠标滚轮实现缩放
在场景中添加一个Plan,Camera,Directional Light,Cube.添加两个脚本scrollerScirpt(挂在Camera),CubeDragScript(挂在Cube上). 1 ...
- ActiveMQ下载及安装
1.下载ActiveMQ 官方网站:http://activemq.apache.org/ 根据需要下载不同的版本.我下载的是5.13.3-win64的版本 2.运行ActiveMQ服务 2.1解压缩 ...