zoukankan      html  css  js  c++  java
  • Expanding Rods(二分POJ1905)

    Expanding Rods
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 13688   Accepted: 3527

    Description

    When a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion.
    When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment.

    Your task is to compute the distance by which the center of the rod is displaced.

    Input

    The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.

    Output

    For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision.

    Sample Input

    1000 100 0.0001
    15000 10 0.00006
    10 0 0.001
    -1 -1 -1
    

    Sample Output

    61.329
    225.020
    0.000
    

    Source

    Waterloo local 2004.06.12

    写了三个公式acos过不了,后来金巨说asin和acos产生的误差atan要大
    #include <set>
    #include <map>
    #include <list>
    #include <stack>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <string>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define PI acos(-1.0)
    using namespace std;
    
    typedef long long LL;
    
    const int MAX = 50010;
    
    const double eps = 1e-5;
    
    double l,c,n;
    double ll;
    bool Judge(double mid)
    {
        double r=(l*l+4*mid*mid)/(8*mid);
        double dis=2*r*asin(l/(2*r));
        //atan(l/(2*(r-mid)));
        if(dis<ll)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    int main()
    {
        while(scanf("%lf %lf %lf",&l,&n,&c))
        {
            if(l==-1&&c==-1&&n==-1)
            {
                break;
            }
            ll=(1+n*c)*l;
            double L=0;
            double R=l/2;
            double ans=0;
            while(R-L>eps)
            {
                double mid = (L+R)/2;
                if(Judge(mid))
                {
                    ans=mid;
                    L=mid;
                }
                else
                {
                    R=mid;
                }
            }
            printf("%.3f
    ",ans);
        }
        return 0;
    }
    


  • 相关阅读:
    允许 使用接口传递对象,为什么?
    一道猫和老鼠吵醒主人的笔试题(C#)
    随心所欲操作Enum枚举类型
    SmartPhone 2003 手机编程实战之一:简单上手 2005年01月08日
    SmartPhone 2003 手机编程实战之二:自己开发一个天气预报服务 2005116
    QQ是危险的、MSN是危险的,所有即时通讯都是危险的
    PWN通用技巧
    Jarvis Oj Pwn 学习笔记level2
    Jarvis Oj Pwn 学习笔记Tell Me Something
    Jarvis Oj Pwn 学习笔记level1
  • 原文地址:https://www.cnblogs.com/juechen/p/5255943.html
Copyright © 2011-2022 走看看