ACM Strange fuction

现在,这里有一个功能:
  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) 
当x在0到100之间时,你能找到最小值吗?

输入

第一行包含一个整数T(1 < = T < = 100),这意味着测试用例的数量。然后T行,每一行只有一个实数Y。(0 < Y < 1e10)当x在0到100之间时,输出值为最小值(精确到小数点后4位)。

Sample Input

2
100
200

Sample Output

-74.4291
-178.8534
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 double der(double mid)
 4 {
 5     return 42*pow(mid,6)+48*pow(mid,5)+21*mid*mid+10*mid;
 6 }
 7 double cacu(double mid,double y)
 8 {
 9     return 6*pow(mid,7)+8*pow(mid,6)+7*pow(mid,3)+5*mid*mid-y*mid;
10 }
11 int main()
12 {
13     int n;
14     double y,left,right,mid;
15     while(cin>>n)
16     {
17         while(n--)
18         {
19             scanf("%lf",&y);
20             left = 0;
21             right = 100;
22             while(right - left > 1e-8)23             {
24                 mid = (left + right) /2;
25                 if(der(mid) - y > 0)
26                     right = mid;
27                 else
28                     left = mid;
29             }
30             printf("%.4lf\n",cacu(mid,y));
31         }
32
33     }
34     return 0;
35 }
时间: 2024-12-29 05:37:37

ACM Strange fuction的相关文章

杭电 HDU ACM Strange fuction

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4124    Accepted Submission(s): 2964 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5933 Accepted Submission(s): 4194 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) C

hdu 2899 Strange fuction (二分)

题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899 题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的x值.注意精确度的问题. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 double y; 6 7 doub

HDU 2899 Strange fuction

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5253    Accepted Submission(s): 3750 Problem Description Now, here is a fuction:  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

hdoj 2899 Strange fuction

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4795    Accepted Submission(s): 3420 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

hdoj 2899 Strange fuction【二分求解方程】

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4599    Accepted Submission(s): 3304 Problem Description Now, here is a fuction:  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

Hdu 2899 - Strange fuction 二分/三分求函数极值点

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4527    Accepted Submission(s): 3251 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

hdu2899——Strange fuction

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3344    Accepted Submission(s): 2446 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

HDU 搜索练习 Strange fuction

Strange fuction Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 97 Accepted Submission(s) : 49 Problem Description Now, here is a fuction:<br>  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <