现在的位置: 首页 > 综合 > 正文

HDU 2199-Can you solve this equation?

2013年02月16日 ⁄ 综合 ⁄ 共 457字 ⁄ 字号 评论关闭

函数单调增,二分做。

代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
double fx(double x)
{
    return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
}
int main()
{
#ifdef test
    freopen("input.txt", "r", stdin);
#endif
    int t;
    double y;
    scanf("%d", &t);
    while(t--)
    {
        double l = 0, r = 100, mid;
        scanf("%lf", &y);
        if(y>=fx(0) && y<=fx(100))
        {
            while(l <= r)
            {
                mid = (l + r) / 2;
                if(fx(mid) > y)
                    r = mid - 1e-7;
                else
                    l = mid + 1e-7;
            }
            printf("%.4lf\n", (r+l)/2);
        }
        else
            printf("No solution!\n");

    }
    return 0;
}

抱歉!评论已关闭.