Strange fuction HDU - 2899 

题意:给定一个Y,求解F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) 的最小值

思路: 随机不知道说什么....

#include<cstdio>
#include<vector>
#include<cmath>
#include<time.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+3;
const int MOD=1e9+7;
const double eps=1e-10;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
double X,Y;
int n;
int sign(double x){
    return fabs(x)<x?0:x<0?-1:1;
}

double mypow(double a,int b){
    double ans=1;
    for(int i=1;i<=b;i++)   ans*=a;
    return ans;
}
double cul(double x){
    return 6*mypow(x,7)+8*mypow(x,6)+7*mypow(x,3)+5*mypow(x,2)-x*Y;
}
double myrand(){
    return rand()%10000/10000.0; ///rand_MAX=2^15-1;
}
void SA(double &res){
    double ans=cul(0.0);
    double X=0.0;
    double T=100;
    while(T>eps){
        double next;
        double mn=1e20;
        for(int i=0;i<50;++i){
            double nx=X+cos(myrand()*2*PI)*T;
            if(sign(nx)<0)  nx=0;
            if(sign(nx-100)>0)  nx=100.0;
            double nE=cul(nx);
            if(nE<mn){
                mn=nE;
                next=nx;
            }
        }

        if(sign(mn-ans)<0 || exp((mn-ans)/T)<myrand()){ ///这里注意胰一下
            ans=mn;
            X=next;
        }
        T*=0.5;
    }
    res=ans;
}
void mian(){
    scanf("%lf",&Y);
    double ans;
    SA(ans);
    printf("%.4f\n",ans);
}
int main(void){
    srand(time(0));
    int T;
    sf(T);
    while(T--){
        mian();
    }

    return 0;
}