NC15886. Mirror
描述
输入描述
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; }