练习二1001
来源:互联网 发布:淘宝卡哪个好 编辑:程序博客网 时间:2024/06/08 04:21
Can you solve this equation?
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 220 Accepted Submission(s) : 83
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>
Author
Redow
Statistic |Submit | Back
题意:
8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,给出y,求出满足条件的x。
思路:
单调函数,用二分法,注意终止条件要小一点,否则得不出结果。
代码:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double zhi(double x)
{
return (8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6);
}
int main()
{
double t,y;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>y;
double low=0,high=100,mid;
if(zhi(0)>y||zhi(100)<y)
cout<<"No solution!"<<endl;
else
{
while(high-low>0.00000001)
{
mid=(high+low)/2;
if(zhi(mid)>y)
high=mid;
else low=mid;
}
cout<<setiosflags(ios::fixed)<<setprecision(4)<<mid<<endl;
}
}
return 0;
}
0 0
- 课程练习二-1001
- 练习二1001
- 练习二1001
- 练习(二)
- 练习二
- 练习二
- 练习二1001 找方程解
- 2016sdau课程练习专题二 1001
- 2016SDAU编程练习二1001
- 练习二 1001找方程的解
- 数据库练习二答案
- 面试练习二
- 基础练习二
- JavaScript练习(二)
- Delphi练习二
- 练习基础题《二》
- 查询练习(二)
- oracle练习(二)
- groovy入门4 闭包简介
- preface
- LeetCode *** 208. Implement Trie (Prefix Tree) (给指针数组赋空间)
- Linux系统下文件的复制和移动命令
- android学习第一天:测试
- 练习二1001
- 2016SDAU编程练习二1024
- C和C++的读入方式对比
- 下蹲运动的好处与练习方式
- 【编程练习】poj1068
- 【usaco 2013 Mar Bronze】
- Linux的SOCKET编程详解
- 在android中实现多线程下载和断点续传
- 面向对象三大特性——封装