社区讨论
站外题求助
学术版参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mdp9mz4p
- 此快照首次捕获于
- 2025/07/30 09:07 7 个月前
- 此快照最后确认于
- 2025/11/04 03:30 4 个月前
题目描述
给定一个实数 ,求 的三次方根。
为什么这个不行(40 TLE)。
CPP#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double y;
double f_(double x){return 3*x*x;}
double f(double x){return x*x*x-y;}
double j(){
double x=y/3;
while(fabs(f(x))>0.001) x=x-f(x)/f_(x);
return x;
}
int main(){
cin>>y;
cout<<fixed<<setprecision(4)<<j();
return 0;
}
而这个可以。
CPP#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double y;
double f_(double x){return 3*x*x;}
double f(double x){return x*x*x-y;}
double j(){
double x=y/3;
for(int i=1;i<=70;i++) x=x-f(x)/f_(x);
return x;
}
int main(){
cin>>y;
cout<<fixed<<setprecision(4)<<j();
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...