UVa --10566
生活随笔
收集整理的這篇文章主要介紹了
UVa --10566
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1507
設(shè) 交點到右端點的距離為 d 底邊長為 L?
則有三角形相似得 ? ? d / L = c / sqrt(y^2 - L^2) ? ? ? ? ? ? ? (1)
? ? ? ?(L - d) / L= c / sqrt(x^2 - L ^2); ? ? ?(2)
由(1)(2)可得 ? 1 - c /?sqrt(y^2 - L^2) ?- c /?sqrt(x^2 - L ^2) = 0;
有上式可得 L越大 左式越小,即為減函數(shù) ?二分求L
#include<stdio.h> #include<math.h> #define min(a,b) (a<b?a:b) double x,y,c; double f(double L) {return 1 - c / sqrt(y*y - L*L) - c / sqrt(x*x - L*L) ; } void search(double y1) {double x1 = 1;double mid ;while(y1 - x1 > 0.00001){mid = (x1 + y1) / 2.0 ;if(f(mid) < 0) y1 = mid;else x1 = mid ;}printf("%.3lf\n",mid);} int main() {while(scanf("%lf%lf%lf",&x,&y,&c)!=EOF){int _min;_min = min(x,y);search(_min);} }
?
總結(jié)
以上是生活随笔為你收集整理的UVa --10566的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue-- $attrs与$listen
- 下一篇: Activiti 多个并发子流程的应用