# 有没有用退火的兄弟

@Imakf 2018-11-02 20:22 回复

@zyywzw 2018-11-02 20:24 回复

@Imakf 2018-11-02 20:27 回复
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
struct func{
double xishu[50];
int ci;
func *dao;
for(int i=ci;i>=0;--i)  scanf("%lf",&xishu[i]);
}
void getdao(){
dao=new func;
for(int i=0;i<ci;++i)
dao->xishu[i]=xishu[i+1]*(i+1);
dao->ci=ci-1;
}
double value(double x){
double ans=0;
for(int i=0;i<=ci;++i){
ans+=pow(x,i)*xishu[i];
}
return ans;
}
double sanfen(double l,double r,double jingdu){
while(l<=r){
double mid=(l+r)/2;
if(fabs(value(mid))<jingdu) return mid;
if(value(mid)>0)    l=mid;
else r=mid;
}
}
};
int main(){
func f;
double l,r;
scanf("%d%lf%lf",&f.ci,&l,&r);
f.getdao();

printf("%.5lf",f.dao->sanfen(l,r,0.00001));
return 0;
}

@TempTest 2018-11-08 15:59 回复

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<ctime>
using namespace std;
typedef double Type;
int n,ans;
Type ansx,l,r,eps=1e-15;
struct function
{
Type factor[20];
Type operator()(Type x)
{
Type ans=0;
for(int i=0;i<=n;i++)
ans+=factor[i]*pow(x,i);
return ans;
}
}f;
void mnth()
{
Type T=100000;
while(T>=eps)
{
Type nowx=ansx+(rand()*2-RAND_MAX)*T,
delta=f(nowx)-f(ansx);
if(delta>0&&l<=nowx&&nowx<=r)ansx=nowx;
else if(exp(delta/T)*RAND_MAX>rand()&&l<=nowx&&nowx<=r)ansx=nowx;
T*=0.99;
}
}
int main()
{
srand(time(NULL)+rand());
cin>>n>>l>>r;
for(int i=n;i>=0;--i)cin>>f.factor[i];
ansx=(l+r)/2;
mnth();
printf("%.5f",ansx);
}