zoukankan      html  css  js  c++  java
  • poj1905Expanding Rods

    http://poj.org/problem?id=1905

    View Code
     1 /*
     2 (1)       角度→弧度公式  θr = 1/2*s
     3 
     4 (2)       三角函数公式  sinθ= 1/2*L/r
     5 
     6 (3)       勾股定理  r^2 – ( r – h)^2 = (1/2*L)^2
     7 整理得
     8 
     9  r = (4*h*h+l*l)/(8*h)
    10  s = 2rarsin(l/(2*r))
    11 
    12 逆向思维解二元方程组:
    13 
    14 要求(1)式的h,唯有先求r
    15 
    16 但是由于(2)式是三角函数式,直接求r比较困难
    17 
    18 因此要用顺向思维解方程组:
    19 
    20 在h的值的范围内枚举h的值,计算出对应的r,判断这个r得到的(2)式的右边  与 左边的值S的大小关系  ( S= (1+n*C)*L )
    21 
    22 */
    23 #include <iostream>
    24 #include<cstdio>
    25 #include<cstring>
    26 #include<stdlib.h>
    27 #include<cmath>
    28 using namespace std;
    29 #define eps 1e-8
    30 int main()
    31 {
    32     double ll,n,c,s,r,low,high,mid;
    33     while(cin>>ll>>n>>c)
    34     {
    35         if(ll<0&&n<0&&c<0)
    36            break;
    37         s = (1+n*c)*ll;
    38         low = 0;high = ll/2;
    39         mid = (low+high)/2;
    40         while(low+eps<high)
    41         {
    42             r = (4*mid*mid+ll*ll)/(8*mid);
    43             double ss = 2*r*asin(ll/(2*r));
    44             if(ss<s)
    45                 low = mid;
    46             else
    47                 high = mid;
    48             mid = (low+high)/2;
    49         }
    50         printf("%.3lf\n",mid+eps);
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    try catch finally
    类的小练习
    易混淆概念总结
    C#中struct和class的区别详解
    Doing Homework again
    悼念512汶川大地震遇难同胞——老人是真饿了
    Repair the Wall
    Saving HDU
    JAVA-JSP隐式对象
    JAVA-JSP动作
  • 原文地址:https://www.cnblogs.com/shangyu/p/2934045.html
Copyright © 2011-2022 走看看