zoukankan      html  css  js  c++  java
  • uva-10341-二分法

    题意:已知方程的根在0-1范围内,求解方程的根,如果方程不存在根,那就输出 no solution.

    直接二分,保留四位小数.

    #include "pch.h"
    #include <string>
    #include<iostream>
    #include<map>
    #include<memory.h>
    #include<vector>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<math.h>
    #include<iomanip>
    
    
    namespace cc
    {
        using std::cout;
        using std::endl;
        using std::cin;
        using std::map;
        using std::vector;
        using std::string;
        using std::sort;
        using std::priority_queue;
        using std::greater;
        using std::vector;
        using std::swap;
        using std::stack;
    
    
        constexpr double MD = 1e-6;
    
        double p, q, r, s, t, u;
    
        double cal(double x)
        {
            return
                p * exp(-x) + q * sin(x) + r * cos(x) + s * tan(x)
                + t * x*x + u;
    
        }
    
        void solve()
        {
            while (cin >> p >> q >> r >> s >> t >> u)
            {
                double l = 0, r = 1;
                if (cal(l)*cal(r) > 0)
                {
                    cout << "No solution" << endl;
                    continue;
                }
                while (r - l > MD)
                {
                    double m = (l + r) / 2;
                    if (cal(m)*cal(l) > 0)
                        l = m;
                    else
                        r = m;
                }
    
                cout << std::setiosflags(std::ios::fixed) << std::setprecision(4) << l << endl;;
    
            }
    
        }
    
    };
    
    
    int main()
    {
    
    #ifndef ONLINE_JUDGE
        freopen("d://1.text", "r", stdin);
    #endif // !ONLINE_JUDGE
        cc::solve();
    
        return 0;
    }
  • 相关阅读:
    Sublime Text3 包管理器、插件安装
    Sublime text3 安装
    VS中的波浪线
    VS的启动方式
    VS常用快捷键
    C#基础性问题
    nginx前端项目发布
    vue父子组件实现数据双向绑定
    常用在线echarts图表
    使用echarts地图踩坑记
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9961227.html
Copyright © 2011-2022 走看看