HDU 1001 Can you solve this equation?
来源:互联网 发布:广州汇丰软件 编辑:程序博客网 时间:2024/05/23 00:11
Problem Description
Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;<br>Now please try your lucky.
Input
The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10);
Output
For each test case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.
Sample Input
2<br>100<br>-4<br>
Sample Output
1.6152<br>No solution!<br>
题目大意:求函数的解
解题思路:套二分模板
感想:……
AC代码:
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
int main()
{
long long int n;
cin >> n ;
while(cin >> n)
{
double min = 0 , max = n;
double mid ;
double res = 1 ;
if(n>=0&&n<=5||n > 807020306) goto p;
while(min <= max)
{
mid = (min + max)/2;
double x = mid ;
if(fabs((8 * x * x * x * x + 7 * x * x * x + 2 * x * x + 3 * x + 6) - n) < 1e-5){
res = x ;
printf("%.4f\n",res);
break;
}
if(8 * x * x * x * x + 7 * x * x * x + 2 * x * x + 3 * x + 6 > n)
max = mid ;
else
min = mid ;
}
p:if(res == 1) cout << "No solution!\n" ;
}
return 0;
}
#include<fstream>
#include<cmath>
using namespace std;
int main()
{
long long int n;
cin >> n ;
while(cin >> n)
{
double min = 0 , max = n;
double mid ;
double res = 1 ;
if(n>=0&&n<=5||n > 807020306) goto p;
while(min <= max)
{
mid = (min + max)/2;
double x = mid ;
if(fabs((8 * x * x * x * x + 7 * x * x * x + 2 * x * x + 3 * x + 6) - n) < 1e-5){
res = x ;
printf("%.4f\n",res);
break;
}
if(8 * x * x * x * x + 7 * x * x * x + 2 * x * x + 3 * x + 6 > n)
max = mid ;
else
min = mid ;
}
p:if(res == 1) cout << "No solution!\n" ;
}
return 0;
}
0 0
- HDU 1001 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199-Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 can you solve this equation
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- iOS开发总结之沙盒存储
- 百度移动SSP启动广告
- 优雅的创建一个相册管理类(兼容AssetsLibrary和PhotoKit)
- xcode提交版本时提示The working copy "MyPro" failed to commit files.解决方法
- java注解
- HDU 1001 Can you solve this equation?
- 数值算法
- BJTU 数学
- zoj 3946Highway Project(最短路改)
- 使用MobAPi获得天气数据
- 说说中断上下文的切换
- java.util包---LinkedHashMap
- UVA_10020_Minimal coverage
- Java编程基础--空指针异常