转化模型就变成几层折射率不同的玻璃光要怎么走才能从(0, 0)到(x, y)
我们发现第一次光线射出去的角度确定,之后光的行程是确定的
而且角度和最后到达y时的x成正相关,于是可以二分!
然后物理学学好就可以了QAQ
1 /************************************************************** 2 Problem: 3695 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:24 ms 7 Memory:820 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <cmath> 12 #include <algorithm> 13 14 using namespace std; 15 typedef double lf; 16 const lf pi = acos(-1.0); 17 const lf eps = 1e-12; 18 const int N = 105; 19 20 lf ans; 21 int n, x; 22 int h[N], v[N]; 23 24 inline lf calc(lf now) { 25 lf res = 0, tmp = 0; 26 int i; 27 for (i = 1; i <= n; ++i) { 28 res += (lf) h[i] / tan(now); 29 tmp += (lf) h[i] / sin(now) / v[i]; 30 now = pi / 2 - asin(sin(pi / 2 - now) * v[i + 1] / v[i]); 31 } 32 ans = tmp; 33 return res; 34 } 35 36 int main() { 37 int i; 38 scanf("%d%d", &n, &x); 39 for (i = 1; i <= n; ++i) scanf("%d", h + i); 40 for (i = 1; i <= n; ++i) scanf("%d", v + i); 41 lf l = 0, r = pi / 2, mid; 42 while (l + eps < r) { 43 mid = (l + r) / 2; 44 if (calc(mid) <= x) r = mid; 45 else l = mid; 46 } 47 printf("%.3lf\n", ans); 48 return 0; 49 }
原文:http://www.cnblogs.com/rausen/p/4354850.html