POJ 1905 二分

题意:

一根细杆长为l,能够压弯成为一段长为(1+n*c)*l 的圆弧。给出l, n, c的值,求出杆变形后,中间升高的距离h

题解:

二分圆心到细杆的距离,然后算出弧长,判断当前二分值的大小是否合适即可

View Code
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <cmath>
 7 
 8 #define PI 3.141592653589793
 9 #define EPS 1e-7
10 
11 using namespace std;
12 
13 double n,l,c,sl;
14 
15 inline int doublecmp(double x)
16 {
17     if(x>EPS) return 1;
18     else if(x<-EPS) return -1;
19     return 0;
20 }
21 
22 inline double getlen(double a,double b)
23 {
24     return sqrt(a*a+b*b);
25 }
26 
27 inline void go()
28 {
29     sl=(1+n*c)*l;
30     double lt=0.0,rt=1000000000.0,mid,af,hc;
31     int cs=500;
32     while(cs--)
33     {
34         mid=(lt+rt)*0.5;
35         af=atan2(l*0.5,mid);
36         af*=2.0;
37         hc=af*getlen(mid,l*0.5);
38         if(doublecmp(hc-sl)>0) lt=mid;
39         else rt=mid;
40     }
41     printf("%.3lf\n",getlen(mid,l*0.5)-mid);
42 }
43 
44 int main()
45 {
46     while(scanf("%lf%lf%lf",&l,&n,&c))
47     {
48         if(l==-1.0&&n==-1.0&&c==-1.0) break;
49         if(doublecmp(l)==0||doublecmp(n)==0||doublecmp(c)==0) puts("0.000");
50         else go();
51     }
52     return 0;
53 }
原文地址:https://www.cnblogs.com/proverbs/p/2924633.html