Strange fuction--hdu2899

Strange fuction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4538    Accepted Submission(s):
3261

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)
Can you find the minimum value
when x is between 0 and 100.

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 only one real numbers Y.(0 < Y <1e10)

Output

Just the minimum value (accurate up to 4 decimal
places),when x is between 0 and 100.

Sample Input

2

100

200

Sample Output

-74.4291

-178.8534

分析:这个题是要求方程的最小值,首先我们来看一下他的导函数: F’(x) = 42 * x^6+48*x^5+21*x^2+10*x-y(0 <= x <=100)

很显然,导函数是递增的,那么只要求出其导函数的零点就行了,下面就是用二分法求零点!

 1 #include<stdio.h>
 2 #include<math.h>
 3 double hs(double x,double y)
 4 {
 5     return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x;//定义一个求函数值得函数
 6 }
 7 double ds(double x,double y)
 8 {
 9     return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;//定义一个求导数的函数
10 }
11 int main()
12 {
13     int a;
14     scanf("%d",&a);
15     while(a--)
16     {
17         double b,x,y,z;
18         scanf("%lf",&b);
19         x=0.0;
20         y=100.0;
21         do
22         {
23             z=(x+y)/2;
24             if(ds(z,b)>0)
25             y=z;
26             else
27             x=z;
28         }while(y-x>1e-6);//求出一定精度内导数为0的大约值
29         printf("%.4lf\n",hs(z,b));
30     }
31     return 0;
32  } 

下面是我刚学的三分法:

 1 #include<stdio.h>
 2 #include<math.h>
 3 double hs(double x,double y)
 4 {
 5     return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x;
 6 }
 7 int main()
 8 {
 9     int n;
10     scanf("%d",&n);
11     while(n--)
12     {
13         double l,r,mid,midmid,a;
14         scanf("%lf",&a);
15         l=0.0;
16         r=100.0;
17         do
18         {
19             mid=(l+r)/2;
20             midmid=(mid+r)/2;
21             if(hs(mid,a)>hs(midmid,a))
22             l=mid;
23             else
24             r=midmid;
25         }while(r-l>1e-6);
26         printf("%.4lf\n",hs(mid,a));
27     }
28     return 0;
29 }
时间: 2024-10-13 15:30:13

Strange fuction--hdu2899的相关文章

HDU2899 Strange fuction 【二分】

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2982    Accepted Submission(s): 2202 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 <=

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

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 <=

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 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 <=

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 <