HNUST专题练习:二分法
2015-04-02 08:30
155 查看
题目:Can you solve this equation?
连接:杭电HNUST专题联练习 1000
思路:对所给函数直接求一阶导和二阶导可知,函数在0~100是单调递增。所以可直接用二分法求解
连接:杭电HNUST专题联练习 1000
思路:对所给函数直接求一阶导和二阶导可知,函数在0~100是单调递增。所以可直接用二分法求解
#include <stdio.h> #include <math.h> int main() { int T; double x1, x2, n, mid,ans1,ans2, ans; scanf("%d", &T); while(T--) { x1 = 0; x2 = 100; scanf("%lf", &n); ans1 = 8 * pow(x1, 4) + 7 * pow(x1, 3) + 2 * pow(x1, 2) + 3 * x1 + 6 - n; ans2 = 8 * pow(x2, 4) + 7 * pow(x2, 3) + 2 * pow(x2, 2) + 3 * x2 + 6 - n; if (ans1 > 0 || ans2 < 0) //如果ans1大于零或者ans2小于零,证明无解 printf("No solution!\n"); else { while (fabs(x1 - x2) >= 1e-8) //限定范围,使得值更精确 { mid= (x1 + x2) / 2; ans = 8 * pow(mid, 4) + 7 * pow(mid, 3) + 2 * pow(mid, 2) + 3 * mid + 6 - n; if (ans >= 0) x2 = mid; else x1 = mid; } printf("%0.4f\n", mid); } } return 0; }
相关文章推荐
- NBUT-2014暑期集训专题练习1 -> 二分法 A题
- NBUT-2014暑期集训专题练习1 -> 二分法E - E
- NBUT-2014暑期集训专题练习1 -> 二分法 J - J
- NBUT-2014暑期集训专题练习1 -> 二分法 N - N
- NBUT-2014暑期集训专题练习1 -> 二分法 H - H
- NBUT-2014暑期集训专题练习1 -> 二分法B - B
- NBUT-2014暑期集训专题练习1 -> 二分法L - L
- NBUT-2014暑期集训专题练习1 -> 二分法F - F
- [kuangbin带你飞]专题四 最短路练习 M POJ 1062
- 【数论】数论专题练习
- 2016sdau课程练习专题一 1006 problemG
- [kuangbin带你飞]专题四 最短路练习-E
- 2016sdau课程练习专题二 1002
- SDAU编程练习二-------二分法and搜索总结
- 2016sdau课程练习专题三 1016
- [kuangbin带你飞]专题四 最短路练习 N POJ 1847
- 水果消除 hnust bfs专题
- 2016sdau课程练习专题四 1006
- poj 1860 Currency Exchange ([kuangbin带你飞]专题四 最短路练习)
- 基本功练习_2_27_之二分法查找