Can you solve this equation?
来源:互联网 发布:淘宝 发货地不符 编辑:程序博客网 时间:2024/05/16 10:40
2<br>100<br>-4<br>
1.6152<br>No solution!<br>
题目大意:
一个多项式,给出y值,让你求x的值。
思路:
将题目看作f(x) = 8*x^47*x^3 2*x^2 3*x 6, x∈[0, 100]时,可以发现整个函数都是递增的,用二分法即可解题
感想:
其实就是一道中学代数题,因为有思路,所以不难,具体就是二分法来做,有引文x<-[0,100]是递增的,所以有规律
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
double f(double x)
{
return (8 * pow(x, 4) + 7 * pow(x, 3) + 2 * pow(x, 2) + 3 * x + 6);
}
using namespace std;
int main()
{
int t;
cin >> t;
for (int i = 0;i<t;i++)
{
double y, mid;
cin >> y;
if (f(0)>y || f(100)<y)cout << "No solution!" << endl;
else
{
double left = 0, right = 100;
while (right - left>1e-10)
{
mid = (right + left) / 2;
if (f(mid)>y)
right = mid;
else left = mid;
}
printf("%.4f\n", mid);
}
}
return 0;
}
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- Can you solve this equation?
- 特殊的算术操作指令详解
- 面试算法题
- 构建之法学习心得3:源代码的合作
- hdoj-1042-N!
- Java中大小端的处理
- Can you solve this equation?
- ES6+React+Webpack初步构建项目流程
- [转载]备忘:VC++6.0 获取其他窗口中文本框内容
- 用keil创建第一个STM32F103RC项目
- Android UI性能优化实战 识别绘制中的性能问题
- CodeForces 557B-Pasha and Tea【模拟】
- [安卓开发] WebView网页隐藏屏蔽广告元素标签|去除底部广告
- Python_Tips[1]
- Win10使用微软语音TTS正确姿势