HDU 2199 Can you solve this equation?(二分)
2017-08-10 21:35
316 查看
Can you solve this equation? |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 1345 Accepted Submission(s): 633 |
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; 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 Input2 100 -4 |
Sample Output1.6152 No solution! |
Author Redow |
Recommend lcy |
#include<iostream> #include<string> #include<cstring> #include<cmath> #include<algorithm> using namespace std; double y; bool c(double x) { double t; t = 8 * x*x*x*x + 7 * x*x*x + 2 * x*x + 3 * x + 6; if (t < y)return true; else return false; } int main() { int t; cin >> t; while (t--) { cin >> y; if (y < 6 || y>807020306) //Y不在0和100之间 { cout << "No solution!" << endl; continue; } double first=0.0; double last=100.0; double mid; for (int i = 0; i < 100; i++)//答案精度管够 { mid = (first + last) / 2; if (c(mid))first = mid;//小了在右边 else last = mid;//大于等于在左边 } printf("%.4lf\n", last); } return 0; }
相关文章推荐
- 文章标题 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(二分水题)
- 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?(二分搜索)