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-; 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 = , r = ;
if (cal(l)*cal(r) > )
{
cout << "No solution" << endl;
continue;
}
while (r - l > MD)
{
double m = (l + r) / ;
if (cal(m)*cal(l) > )
l = m;
else
r = m;
} cout << std::setiosflags(std::ios::fixed) << std::setprecision() << l << endl;; } } }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return ;
}
上一篇:google auth


下一篇:敏捷视界:Scrum起源、Scrum术语