zoukankan      html  css  js  c++  java
  • poj1905

    题意:给出膨胀指数,加热温度,杆子的原长度,问加热后的杆子两端点位置不变,弯曲成弧,圆心的位置。

    分析:二分答案,二分查找圆心位置,根据圆心位置计算出弧长与原弧长比较,不知道为什么wa那么多次。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cmath>
    usingnamespace std;

    #define eps 1.0e-8

    double c, l1, n;

    double cal(double b)
    {
    double a = l1 /2;
    double d = sqrt(a * a + b * b);
    double h = a * d / b;
    double r = sqrt(h * h + d * d) /2;
    return atan(b / (l1 /2)) *4* r;
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    while (scanf("%lf%lf%lf", &l1, &n, &c) != EOF)
    {
    if (n <0&& l1 <0&& c <0)
    break;
    double l2 = l1 * (n * c +1);
    if (l2 - l1 < eps)
    {
    printf(
    "0.000\n");
    continue;
    }
    double l = eps;
    double r = l1 /2;
    double mid;
    while (abs(l - r) > eps)
    {
    mid
    = (l + r) /2;
    double x = cal(mid);
    if (abs(x - l2) < eps)
    break;
    if (x > l2)
    r
    = mid - eps;
    else
    l
    = mid + eps;
    }
    printf(
    "%.3f\n", mid);
    }
    return0;
    }
  • 相关阅读:
    324. Wiggle Sort II
    341. Flatten Nested List Iterator
    300. Longest Increasing Subsequence
    72. Edit Distance
    63. Unique Paths II
    221.Maximal Square
    House Robbers. 198 & 213
    [C++] 与比较有关的事情
    218.The Skyline Problem
    41. First Missing Positive
  • 原文地址:https://www.cnblogs.com/rainydays/p/2096471.html
Copyright © 2011-2022 走看看