文章
35
粉丝
599
获赞
6
访问
309.8k
ac不了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
double f(double x)
{
return pow(x,(double)1/2)+pow(x,(double)1/3);
}
//int roundx(double number)
//{
//return (number>0.0)?(number+0.5):(number-0.5);
//}
double roundx(double number,int bits) //number->浮点数,bits->保留位数
{
for(int i=0;i<bits;++i)
{
number*=10;
}
number=(long long)(number+0.5);
for(int i=0;i<bits;++i)
{
number/=10;
}
return number;
}
double dao(int y,double l,double h)
{
double mid=(l+h)/2;
if(h-l>=10e-11)
{
//cout<<"h-l="<<h-l<<" mid="<<mid<<" f(mid)="<<f(mid)<<endl;
if(f(mid)==y)
{
return mid;
}
if(f(mid)>y)
return dao(y,l,mid);
if(f(mid)<y)
return dao(y,mid,h);
}
return mid;
}
int main()
{
int n,y;
cin>&...
登录后发布评论
你这个代码精度丢失了,输入5的时候你的输出是8.6747045116,正确输出是:8.6747045115