题意:解方程组,一共6项,对每项没来说有的是增函数,有的是减函数,但是由于系数的限制,所有加上系数后都是减函数,整个函数为减。
方法:二分查找。
注意:setprecision限制小数点,必须加上fixed,否则WA,亲测。
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
using namespace std;
#define cal(x) (p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u)
double p, q, r, s, t, u;
int main()
{
#ifdef Local
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#endif
while (cin >> p >> q >> r >> s >> t >> u)
{
if (cal(0) < 0 || cal(1) > 0)
cout << "No solution" << endl;
else
{
double x1 = 0, x2 = 1;
while (fabs(x1 - x2) >= 1e-10)
{
double x = (x1 + x2)/2;
if (cal(x) > 0)
x1 = x;
else
x2 = x;
}
cout << setprecision(4) << fixed << x1 << endl;;
}
}
return 0;
}