二分_B
来源:互联网 发布:php开发实战教程 编辑:程序博客网 时间:2024/05/16 15:55
Description
现在,给出等式8* X^4+ 7* X^3+ 2* X^2+ 3 * X +6= Y,请找出他在0和100之间的解(包含0和100)。
现在,请你试试运气。。。。
Input
输入的第一行包含一个整数T(1 <= T <=100),表示测试用例的数目。接下来T个数字,每一行都有一个实数Y(abs(Y)<=10^10);
Output
对于每个测试用例,如果有解,你应该输出一个实数(精确到小数点后4位,四舍五入),如果在0到100之间无解,就输出“No solution!”。
Sample Input
2
100
-4
Sample Output
1.6152
No solution!
这是一个单调函数,在0~100利用二分找出,注意精度,一般1e-7即可
#include<iostream>#include"math.h"#include<cstdio>using namespace std;#define EPS 1e-5double f(double x){ return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;}double binary(double y){ double low=0.0,height=100.0; double mid=(low+height)/2.0; while(fabs(y-f(mid))>EPS){ mid=(low+height)/2.0; if(f(mid)<y) low=mid; else height=mid; } return mid;}int main(){ int T; double a; cin>>T; while(T--){ cin>>a; if(f(0)>a||f(100)<a) {cout<<"No solution!"<<endl;continue;} printf("%0.4lf\n",binary(a)); } return 0;}
0 0
- 二分_B
- 立业_b
- 数据结构_B树
- 消息机4_B
- 7.12归来赛_B
- 7.14_B题
- 7.16_B题
- Round #232 (Div. 2)_B
- NickLee.FortuneBase(2008.3_B) For Oracle11g
- NickLee.FortuneBase(2008.4_B) For Oracle11g
- NickLee.FortuneBase(2009.1_B) For Oracle11g
- NickLee.FortuneBase(2011.1_B) For Oracle 11
- A::A() : _b(XXX,XXX)解析
- 学习 Linux高级编程05_B
- 学习 Linux高级编程06_B
- 学习 Linux高级编程07_B
- 学习 Linux高级编程08_B
- 学习 Linux高级编程09_B
- 各种排序算法的总结和比较
- Simple UI Component
- Java NIO框架Netty简单使用
- Android从Fragment中跳转到Activity
- Educational Codeforces Round 14 C 好东西啊!!!
- 二分_B
- Spring(1)--初识Spring之HelloWorld
- 模仿新浪微博刷新显示多少条数据
- xibyu约束scrollerview
- 二分法,递归和非递归方式 实现(Java)
- Integer与int的区别
- ollydbg 调试
- SpringMVC环境快速搭建
- Map的五种遍历方法