列表

详情


NC15886. Mirror

描述

It’s universally acknowledged that there’re innumerable trees in the campus of HUST. DK placed two straight mirrors with infinite length alongside the street, one for each side. DK also has built a laser emitter underground, right under the street. One day DK finds Alisa walking on the street carrying a bunch of trees. Since DK wants to play a trick on Alisa, DK then comes up with an idea that he can use his laser emitter to burn out those trees. However, he must make sure he’ll not be spotted. Mirrors are placed on lines 𝑦 = 0 and 𝑦 = 1, DK’s laser emitter is placed at (0,𝑟), and has a fixed laser direction (𝑔,ℎ). Then the laser will travel in area {(𝑥,𝑦)|0 ≤ 𝑥,0 ≤ 𝑦 ≤ 1}. The intensity of a point that laser light passing by is defined as 𝐼 = , where 𝐼0 is laser emitter’s strength and 𝑑 is the distance of light travelling. Alisa stands at (𝑎,𝑏). DK is to place a small mirror that will reflect laser once and only once. DK will use this mirror to redirect the laser so that the laser can hit Alisa’s trees. Tell DK where he should place the mirror, so that the intensity of light that trees received is exactly 𝑇.


输入描述

The first line contains r(0<r≤1).
The second line contains a pair of number g(0<g≤100) and h(0<h≤100).
The third line contains two number I0(1≤I0≤100) and I(1≤I≤100).
The fourth line contains a(0<a≤1) and b(0<b≤1).
All input data are real number with 2 digits after point.

输出描述

A single line that contains the x coordinate where the mirror reflects the laser. You can assume that there's always at least one solution.

Your answer is considered correct IFF the relative difference of your solution’s light intensity and required intensity on Alisa’s trees is less than10-6.

示例1

输入:

0.50
0.50 0.44
14.50 0.32
0.17 0.96

输出:

2.959059584703

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 504K, 提交时间: 2018-05-17 18:49:01

#include<bits/stdc++.h>
using namespace std;

const double eps = 1e-7;
double r;
double g, h;
double I, T;
double a, b;

double f(double x)
{
    double len = sqrt(g*g + (h-r)*(h-r)) / g;
    double tmp = (h - r) / g;
    double x1 = (-r * g) / (h - r);
    double x2 = (1 - r)*g / (h - r);
    double L = fabs(2*g / (h - r));
    if (x1 > x2) swap(x1, x2);
    int ll = 0, rr = 1e9;
    int k;
    //cout << x1 << ' ' << x2 << ' ' << L << endl;
    while (ll < rr)
    {
        k = (ll + rr) / 2;
        if (x >= x1 + k*L && x < x1 + (k + 1)*L)
            break;
        else if (x >= x1 + (k + 1)*L) ll = k + 1;
        else if (x < x1 + k*L) rr = k;
    }
    double x0 = x - k*L;
    double y;
    if (x0 < x1 + L/2) y = tmp * x0 + r;
    else y = tmp * (2*x2 - x0) + r;
    //cout << k << ' ' << x0 << ' ' << y << endl;
    double dis = sqrt((x-a)*(x-a) + (y-b)*(y-b));
    return len*x + dis;
}

int main(void)
{
    cin >> r;
    cin >> g >> h;
    cin >> I >> T;
    cin >> a >> b;
    h += r;
    double x;
    double ans = 0;
    double l = 0, r = 1e9;
    double tar = I / T;
    while (fabs(l - r) > eps)
    {
        x = (l + r) / 2;
        ans = f(x);
        if (ans * ans > tar) r = x;
        else l = x;
    }
    //f(87.234);
    printf("%.8f\n", l);
    return 0;
}

上一题