ʕ·͡ˑ·ཻ ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ

题目 - Strange fuction

Now, here is a fuction:
F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (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

1
2
3
2
100
200

Sample Output

1
2
-74.4291
-178.8534

题意:

​ 输入y的值,大致估算该函数的最小值

AC代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<algorithm>

using namespace std;

const double eps=1e-8;

double y;

int dir[2]={1,-1};

double f(double x)
{
return 6*pow(x,7) + 8*pow(x,6) + 7*pow(x,3) + 5*pow(x,2) - y*x;
}

double anneal()
{
double T=100;
double delta=0.98;
double x=50.0;
double now=f(x);
double ans=now;
while(T>eps)
{
double nowx=x+dir[rand()%2]*T;
if(nowx>=0.0 && nowx<=100.0)
{
now=f(nowx);
if(ans-now>eps)
{
ans=now;
x=nowx;
}
}
T*=delta;
}
return ans;
}

int main()
{
int i,j;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&y);
printf("%.4lf\n",anneal());
}
return 0;
}