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 ...
随机推荐
- IOS 特定于设备的开发:处理基本方向
UIDevice类使用内置的orientation属性获取设备的物理方向.IOS设备支持这个属性的7个可能的值. >UIDeviceOrientationUnknown:方向目前未知. > ...
- Python2.7.3 学习——第一个程序 Hello Python World
Hello World 每学一门语言开始的第一程序都是Hello World ,当然了Python也不例外,下面开始我们的Python第一个程序编写: 1,命令行: (1)打开终端,输入python, ...
- html 实现网址链接
<a href="http://acm.nyist.net/JudgeOnline/problemset.php">南工oj</a> HTML学习 < ...
- 射频识别技术漫谈(29)——射频接口芯片TRF7960
TRF7960系列是TI推出的载波为13.56MHz.支持ISO15693.ISO14443A/B和FeliCa协议的射频接口芯片.许多人更关心它能不能读写MF1卡片,就我的理解及实际验证,由于MF1 ...
- GitHub Android 最火开源项目Top20 GitHub 上的开源项目不胜枚举,越来越多的开源项目正在迁移到GitHub平台上。基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要。利用这些项目,有时能够让你达到事半功倍的效果。
1. ActionBarSherlock(推荐) ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便 ...
- Echoprint系列--Android编译与调用
在Echoprint系列--编译中编译了源代码,这次将Echoprint移植到Android平台并測试识别歌曲功能. 一.编译库 1.环境准备 Android NDK,我的是android-ndk-r ...
- swift菜鸟入门视频教程-03-字符串和字符
本人自己录制的swift菜鸟入门,欢迎大家拍砖.有什么问题能够在这里留言. 主要内容: 字符串字面量 初始化空字符串 字符串可变性 字符串是值类型 使用字符 计算字符数量 连接字符串和字符 字符串插值 ...
- CentOS 6.4 U盘启动盘制作、安装及遇到的问题解决
用UltraISO Premium Edition 9.3 制作的CentOS 6.4 U盘安装盘, 制作过程參考我写的百度经验:UltraISO制作U盘系统盘安装CentOS经验分享 安装时提示P ...
- WCF 双工通信
注释:本学习是参考Artech大神的资料: 在WCF 实现双工通信 在这里我就不介绍双工通信的概念了,我写博客的目的是检测自己掌握情况,看我wcf通信后,觉得纸上得来终觉浅,绝知此事要躬行. 我使用的 ...
- Cookie获取、设置值
设置: HttpCookie cookie = new HttpCookie("cookieName"); cookie.Value = "name1" Htt ...