zoukankan      html  css  js  c++  java
  • UVA10566计算几何+相似三角形比例函数+二分范围的辨析

     1 /*UVA10566
     2 平面几何:
     3 相似三角形,公式法。
     4 但是关键是设变量角度rad,通过分析,可知计算出来的y是一个单调函数,当y恰好等于给定y时,对应的角度就是解题的关键
     5 这样,就可以通过二分逼近答案了
     6 but,but,but;
     7 调试过程中,发现是一个凸函数,故转而用三分解决。
     8 but,but,but;
     9 答案不对,最终知道,还是二分,为什么像三分呢,因为二分变量的取值范围不对了。(这点是日后要注意的)
    10 所以下次尽量保证代数式的范围正确性
    11 */
    12 #include<iostream>
    13 #include<stdio.h>
    14 #include<string.h>
    15 #include<algorithm>
    16 #include<stdlib.h>
    17 #include<cmath>
    18 #include<queue>
    19 #include<vector>
    20 #include<map>
    21 #define LL long long
    22 
    23 using namespace std;
    24 
    25 double x,y,c;
    26 double F(double rad)//F是单调递减函数
    27 {
    28     double d,d1,d2,Y;
    29     d=x*cos(rad);
    30     d2=c/tan(rad);
    31     d1=d-d2;
    32     Y=d*sqrt(d1*d1+c*c)/d1;
    33     return Y-y;
    34 }
    35 int main()
    36 {
    37     while(cin>>x>>y>>c)
    38     {
    39         double L=asin(c/x)+1e-7,R=M_PI/2-L;
    40         int t=0;
    41         while(t<100)
    42         {
    43             t++;
    44             double m=(R+L)/2;
    45             if(F(m)<0) R=m;else L=m;
    46         }
    47 //        for(double i=asin(c/x)+0.001;i<M_PI/2;i=i+0.1) cout<<i<<","<<F(i)<<endl;
    48 
    49         printf("%.3lf
    ",x*cos(L));
    50     }
    51     return 0;
    52 }
  • 相关阅读:
    OCP-1Z0-053-V12.02-668题
    Oracle DB 监控和优化RMAN
    OCP-1Z0-052-V8.02-123题
    OCP-1Z0-053-V12.02-151题
    OCP-1Z0-053-V12.02-66题
    OCP-1Z0-053-V12.02-163题
    OCP-1Z0-052-V8.02-51题
    OCP-1Z0-052-V8.02-53题
    ostringstream、istringstream、stringstream
    OCP-1Z0-053-V12.02-205题
  • 原文地址:https://www.cnblogs.com/little-w/p/3570201.html
Copyright © 2011-2022 走看看