Program B--CodeForces 492B
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 题目大意:Vanya走在一条长为l的街上,这条街上有n盏灯,这n盏可以在l上的随意位置,所以灯照射的半径都相同,求灯的最小半径使得整条街都有光照。 注意:任意两盏灯必须要相邻才行。 分析:这题可以直接用暴力求解,不过要注意两点。首先n盏灯中包括左右两个端点,则只要知道其中两盏灯距离最大(用sum表示)就可以了, 它的一半就是要求的最小半径; 如果只包括其中一个端点或两个端点都不包括,先将左端点到第一盏的灯距离(用c表示)与最后一盏灯到右端点的距离(用d表示)进行比较, 取较大的值赋给c,由于c本身就是半径,所以如果c的2倍大于或等于距离最大的两盏灯,输出c,否则输出sum的一半。 代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,l,a[1005],c,p,q,flag,i,d;
double sum;
while(scanf("%d%d",&n,&l)==2)
{
c=0,d=0,p=0,q=0,sum=0.0,flag=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(i=0;i<n&&a[i]<=l;i++)
{
if(a[0]==0&&a[n-1]==l)
flag=1;
q=a[i]-p;
p=a[i];
if(q>=sum)
sum=q;
}
if(!flag)
{
if(a[0]!=0)
c=a[0];
if(a[n-1]!=l)
d=l-a[n-1];
c=max(c,d);
if(2*c>=sum)
printf("%.10lf\n",(double)c);
else
printf("%.10lf\n",sum/2); }
else
printf("%.10lf\n",sum/2); }
return 0;
}
Program B--CodeForces 492B的更多相关文章
- Codeforces 492B B. Vanya and Lanterns
Codeforces 492B B. Vanya and Lanterns 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- codeforces 492B. Vanya and Lanterns 解题报告
题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...
- CodeForces 492B
Description Vanya walks late at night along a straight street of length l, lit by n lanterns. Consid ...
- Codeforces 492B Name That Tune ( 期望DP )
B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- [Benchmark] Codeflaws: A Programming Competition Benchmark for Evaluating Automated Program Repair Tools
Basic Information Publication: ICSE'17 Authors: Shin Hwei Tan, Jooyong Yi, Yulis, Sergey Mechtaev, A ...
- Codeforces Round #443 (Div. 1) A. Short Program
A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...
- Codeforces Round #879 (Div. 2) C. Short Program
题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- Codeforces Round #443 (Div. 2) C. Short Program
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 879C/878A - Short Program
传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...
随机推荐
- 工作了3年的JAVA程序员应该具备什么技能?(zhuan)
http://www.500d.me/article/5441.html **************************************** 来源:五百丁 作者:LZ2016-03-18 ...
- maven install 报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project*****
[ERROR]Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-co ...
- 通用 PE 工具箱1.9.6(XP内核)by Uepon(李培聪)
通用 PE 工具箱1.9.6(XP内核)by Uepon(李培聪)官网:http://hi.baidu.com/uepon?page=21.8版论坛帖子:http://bbs.wuyou.net/fo ...
- (x&y) + ((x^y)>>1)即x和y的算数平均值
(x&y) + ((x^y)>>1)相当于(x+y)/2 (x&y)+((x^y)>>1),把x和y里对应的每一位(指二进制位)都分成三类,每一类分别计算平均值 ...
- 有关Flash Player的内存管理及泄露检测
1.Flash Player分配内存的策略是少量请求大内存块, 也就是不会频繁向系统请求内存. 2.Flash Player内存的回收是根据引用计数和标记清除(比较耗cpu)这两种方法. 3.从理论上 ...
- 自己动手做jQuery插件
前言:这种东西随意可以在网上收到,这里我还是只是记下自己的见解和领. 第一种方式 (function ($) { $.extend({ sayHello: function (name) { aler ...
- Ubuntu 安装 Redis
1. 下载并安装 redis 2.6.16版 sudo mkdir /usr/local/src/Redis cd /usr/local/src/Redis sudo wget http://down ...
- 背景大图隔几秒切换(非轮播,淡入淡出)--变形金刚joy007 项目总结
工作日想了好久,周日回家才想出来的... 图片切换(非轮播,淡入淡出) 1.切换2.停止 <html> <head> <meta content="text/h ...
- C#引用Office.word出错的解决办法-无法嵌入互操作类型“Microsoft.Office.Interop.Word.ApplicationClass” 【转】
本文章转自 suchso 1.系统找不到 Microsoft.Office.Interop.Word" "Could not load file or assembly 'Micr ...
- Linux基础: 系统加载过程和运行级别含义
BIOS 有固化代码指向mbr,mbr指向grub(/boot/grub/下有很多引导配置信息),grub里可以配置多种linux内核vmlinux文件. 启动内核以后就开始加载各种驱动模块并进行系统 ...