ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#206420 | #1745. 一元三次方程求解 | Matthew | 100 | 0ms | 1300kb | C++ | 775b | 2024-07-22 18:27:20 | 2024-07-22 20:07:04 |
answer
#include <bits/stdc++.h>
using namespace std;
double p;
double a,b,c,d;
map<double,bool> mp;
double f(double x){
return x*x*x*a+x*x*b+x*c+d;
}
double F(double x){
return 3*x*x*a+2*x*b+c;
}
double P(double x){
return (F(x)*x-f(x))/F(x);
}
vector<int> V;
//位于(x,f(x))斜率是F(x),
//y=F(x)x+k
//f(x)=F(x)x+k
//k=f(x)-F(x)*x
//y=F(x)t+f(x)-F(x)*x
//t=(-f(x)+F(x)*x)/F(x)
bool s[114514];
int main(){
cin >> a >> b >> c >> d;
for(double x = -114;x <= 114;x+=0.6){
if(f(x)*f(x+1)<0||(f(x)!=0&&f(x+1)==0)){
p=x;
while(abs(f(p))>=0.01)p=P(p);
if(mp[floor(100*p)/100.0])continue;
mp[floor(100*p)/100.0]=1;
printf("%.2lf ",p);
}
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 25
Accepted
time: 0ms
memory: 1292kb
input:
1 -2 -1 2
output:
-1.00 1.00 2.00
result:
ok single line: '-1.00 1.00 2.00 '
Test #2:
score: 25
Accepted
time: 0ms
memory: 1300kb
input:
1 -4.65 2.25 1.4
output:
-0.35 1.00 4.00
result:
ok single line: '-0.35 1.00 4.00 '
Test #3:
score: 25
Accepted
time: 0ms
memory: 1296kb
input:
1 10 -1 -10
output:
-10.00 -1.00 1.00
result:
ok single line: '-10.00 -1.00 1.00 '
Test #4:
score: 25
Accepted
time: 0ms
memory: 1300kb
input:
1 -1.8 -8.59 -0.84
output:
-2.10 -0.10 4.00
result:
ok single line: '-2.10 -0.10 4.00 '