LightOJ 1137 - Expanding Rods 基础计算几何

http://www.lightoj.com/volume_showproblem.php?problem=1137

 

题意:一根长度为L的杆热膨胀为L',左端点到右端点间距离不变,且膨胀后的杆的弧为圆形的一部分。

思路:由于弧度值是固定在0~PI间,所以直接二分弧度制,通过初中学的弧度公式换算一下就行了,之前精度总是达不到要求,其实eps设的更小点就行了...

/** @Date    : 2016-12-11-21.41
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version :
  */
#include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-15;
const double PI = acos(-1.00);


int main()
{
    int T;
    int cnt = 0;
    cin >> T;
    while(T--)
    {
        double l, n, c;
        cin >> l >> n >> c;
        double lx = l * (1 + n * c);

        double ll = 0;
        double rr = PI;
        double ans = -1;
        while(fabs(ll - rr) > eps)
        {
            double m = (ll + rr) / 2.00;
            double r = lx / m;
            double ly = 2*r * sin(m / 2);
            ans = lx / m * (1 - cos(m / 2));
            if(fabs(ly - l) < eps)
                break;
            else if(ly < l)
                rr = m;
            else if(ly > l)
                ll = m;
            //cout << ly << endl;
        }
        printf("Case %d: %.9lf\n", ++cnt, ans);
    }
    return 0;
}

posted @ 2016-12-12 09:37  Lweleth  阅读(239)  评论(0编辑  收藏  举报