CodeForces - 908C (暴力枚举)

127 篇文章 0 订阅
85 篇文章 2 订阅

C. New Year and Curling

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Carol is currently curling.

She has n disks each with radius r on the 2D plane.

Initially she has all these disks above the liney = 10100.

She then will slide the disks towards the line y = 0 one by one in order from 1 to n.

When she slides the i-th disk, she will place its center at the point (xi, 10100.

). She will then push it so the disk’s y coordinate continuously decreases, and x coordinate stays constant. The disk stops once it touches the line y = 0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.

Compute the y-coordinates of centers of all the disks after all disks have been pushed.

Input

The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively.

The next line will contain n integers x1, x2, …, xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.

Output

Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6.

Namely, let’s assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker program will consider your answer correct if for all coordinates.

Example

input

6 2
5 5 6 8 3 12

output

2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613

Note

The final positions of the disks will look as follows:
这里写图片描述
In particular, note the position of the last disk.

问题分析

题意:从上面往下落球,如果球达到y坐标为0时或者碰到其他球都会停止。给出球的半径和每个球的横坐标,求最后每个球的圆心Y坐标。

每当下落一个球,就去判断它会和哪个球碰到,枚举可以和它发生碰撞的球的最高y坐标加上高度即可(h = sqrt(4*r*r-x*x)勾股定理)。
这里写图片描述
好,下面是AC code(^_^)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
const int N = 1500;
int v[N];
double ans[N];
int main()
{
    // freopen("in.txt","r",stdin);
    int n,r;
    cin>>n>>r;
    for(int i = 0; i < n; i++)
    cin>>v[i];
    int t = (r+r)*(r+r);
    for(int i = 0; i < n; i++)
    {
        int x;double temp = r;
        for(int j = 0; j < i; j++)
        {
            x = fabs(v[i]-v[j]);
            if(x<=2*r)//碰撞条件
            {
                temp = max(ans[j]+sqrt(fabs(t-x*x)),temp);
            }
        }
        ans[i] = temp;
        printf("%.10f ",ans[i]);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值