197 条题解
-
03300284 LV 9 @ 2014-02-19 22:27:33
我吐槽楼下所有人,我靠,全是错代码,还发的一身劲
以下是被坑了N次后终于长一智写出的代码(还是靠自己好)
program sanci;
var i:integer;
x,f,a,b,c,d:real;
begin
readln(a,b,c,d);
x:=-100.00;
for i:=1 to 20000 do
begin
x:=x+0.01;
f:=a*x*x*x+b*x*x+c*x+d;
if abs(f)<0.000001 then write(x:0:2,' ');
end;
end. -
02014-02-12 11:35:51@
var a,b,c,d,x,total,i:longint;
x1,x2,xx:extended;
ans:array[1..100] of extended;
procedure print;
begin
inc(total);
ans[total]:=x1;
end;
function f(x:extended):extended;
begin
f:=a*x*x*x+b*x*x+c*x+d;
end;
begin
total:=0;
readln(a,b,c,d);
for x:=-100 to 100 do
begin
x1:=x; x2:=x+1;
if f(x1)=0 then print
else
if (f(x1)*f(x2)<0) then
begin
while x2-x1>=0.001 do
begin
xx:=(x2+x1)/2;
if (f(x1)*f(xx) <=0)
then x2:=xx else x1:=xx;
end;
print;
end;
end;
for i:=1 to 2 do write(ans[i]:0:2,' '); write(ans[3]:0:2);
end. -
02013-12-15 09:56:24@
#include<cstdio>
#include<iostream>
using namespace std;double a,b,c,d;
double f(double x)
{
double x2,x3;
x2=x*x;
x3=x2*x;
return a*x3+b*x2+c*x+d;
}int main()
{
double l,r,m;
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
for (int i=-100;i<100;i++)
{
l=i;r=i+1;
if (f(l)==0) printf("%.2lf ",l);
else if (f(l)*f(r)<0)
{
m=(l+r)/2;
while (r-l>0.001)
{
if (f(l)*f(m)<0) r=m;else l=m;
m=(l+r)/2;
}
printf("%.2lf ",m);
}
}
return 0;
} -
02013-12-15 09:22:01@
#include<cstdio>
using namespace std;
int main(){
double a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
for (double i=-100;i<=100;i+=0.001)
{
double j=i+0.001;
double y1=a*i*i*i+b*i*i+c*i+d;
double y2=a*j*j*j+b*j*j+c*j+d;
if (y1>=0 && y2<=0||y1<=0 && y2>=0){
double x=(i+j)/2;
printf("%.2lf ",x);
}
}
} -
02013-10-29 22:36:08@
#include<iostream>
#include<iomanip>
using namespace std;
const float m=.001;
int main(){
float a,b,c,d,x,f1,f2;
int i=0;
cin>>a>>b>>c>>d;
for(x=-100;x<=100;x+=m){
f1=a*(x-m)*(x-m)*(x-m)+b*(x-m)*(x-m)+c*(x-m)+d;
f2=a*(x+m)*(x+m)*(x+m)+b*(x+m)*(x+m)+c*(x+m)+d;
if(f1*f2<0){
cout<<setiosflags(ios::fixed)<<setprecision(2)<<x<<" ";
i+=1;
x+=m;
}
if(i==3)break;
}
return 0;
} -
02013-10-27 21:19:14@
var
a,b,c,d,i,s,t,min1,min2,min3,ans1,ans2,ans3:real;
begin
readln(a,b,c,d);
i:=-100.01;
min1:=10000000000000;
min2:=min1;
min3:=min1;
while i<=100 do
begin
i:=i+0.01;
s:=abs(a*i*i*i+b*i*i+c*i+d);
if s<min1 then
begin
min3:=min2;ans3:=ans2;
min2:=min1;ans2:=ans1;
min1:=s;ans1:=i;
end
else if s<min2 then
begin
min3:=min2;ans3:=ans2;
min2:=s;ans2:=i;
end
else if s<min3 then
begin
min3:=s;ans3:=i;
end;
end;
if ans1>ans2 then
begin
t:=ans1;
ans1:=ans2;
ans2:=t;
end;
if ans1>ans3 then
begin
t:=ans1;
ans1:=ans3;
ans3:=t;
end;
if ans2>ans3 then
begin
t:=ans2;
ans2:=ans3;
ans3:=t;
end;
writeln(ans1:0:2,' ',ans2:0:2,' ',ans3:0:2);
end.
枚举秒过。
二分都是浮云。 -
02013-10-05 17:32:17@
16行代码C++
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double a,b,c,d;
cin>>a>>b>>c>>d;
for (double i=-100;i<=100;i+=0.001){
double j=i+0.001;
double y1 = a*i*i*i+b*i*i+c*i+d;
double y2 = a*j*j*j+b*j*j+c*j+d;
if (y1>=0 && y2<=0||y1<=0 && y2>=0){
double x=(i+j)/2;
cout<<setprecision(2)<<std::fixed<<x<<" ";
}
}
} -
02013-08-10 17:45:36@
这数据弱了点
-
02013-07-15 11:10:35@
var a,b,c,d,x1,x2:double;
function f(x:double):double;
begin
f:=a*x*x*x+b*x*x+c*x+d;
end;
function search(a,b:double):double;
var mid:double;
begin
if abs(f(a))<=0.000001 then exit(a);
if abs(f(b))<=0.000001 then exit(b);
mid:=(a+b)/2;
if abs(f(mid))<=0.000001 then exit(mid);
if f(a)*f(mid)<0 then search:=search(a,mid)
else search:=search(mid,b);
end;
begin
read(a,b,c,d);
x1:=(-2*b-2*sqrt(b*b-3*a*c))/(6*a);
x2:=(-2*b+2*sqrt(b*b-3*a*c))/(6*a);//导数求出单调区间
write(search(-100,x1):0:2,' ');//2分法
write(search(x1,x2):0:2,' ');
write(search(x2,100):0:2);
end. -
02013-04-02 22:50:39@
var
a,b,c,d,e:real;
i,j:integer;
begin
readln(a,b,c,d);
for i:=-10000 to 10000 do
begin
e:=i/100;
if abs(e*e*e*a+e*e*b+e*c+d)<=0.000001 then
begin
write(re:0:2,' ');
inc(j);
if j=3 then halt;
end;
end;
readln;
readln;
end. -
02012-11-09 11:37:30@
目测较水。。。。。。。
点这里查看程序源码+详细题解
-
02012-11-02 20:55:51@
#include
#define f(x) (a*x*x*x+b*x*x+c*x+d)
#define E 1e-2
double a,b,c,d;
double findsol(double x1,double x2) { //二分法
double xmid=(x1+x2)/2;
if(x2-x1 -
02012-10-23 22:16:23@
楼下废话,这跟解在—100到100“有什么区别?
-
02012-07-26 15:12:45@
首先确定三个根的分布情况:
已知该多项式在[-100,100]内有三个根,说明函数图像穿过x轴三次,易知在该区间内f(x)取得两次局部极值,设分别在d1,d2两个点取到,那么三个根一定分别分布在[-100,dx1],[dx1,dx2],[dx2,100]内。
在这三个区间上分别二分法求根即可 -
02012-07-21 11:43:57@
其实很简单,大家不要想复杂啦
按照题目的提示,枚举x,因为x精确小数点后两位,
如果f(x)*f(x+0.01) -
02010-07-05 18:50:38@
var a, b, c, d, x1, x2, e:real;
i, j:integer;
function fac(x:real):real;
begin
fac:=a*(x*x*x)+b*(x*x)+c*x+d;
end;
begin
readln(a, b, c, d);
for i:=-10000 to 10000 do begin
x1:=(i/100)+0.00001;
x2:=(i/100)-0.00001;
if (fac(x1)*fac(x2) -
02010-04-10 18:42:43@
program three;
var
a,b,c,d,x,i,j,tem:real;
procedure int;
begin
readln(a,b,c,d);
end;
function f(x,a,b,c,d:extended):extended;
begin
f:=a*x*x*x+b*x*x+c*x+d;
end;
procedure try;
begin
i:=-100;
repeat
j:=i+0.01;
if f(i,a,b,c,d)*f(j,a,b,c,d) -
02009-11-03 14:07:01@
for i:=-100000 to 100000 do
begin
x:=i/1000;
if (-0.0000000001 -
02009-11-02 21:42:04@
有那么复杂?
#include
#include
using namespace std;int main(int argc, char* argv[]){
double a=0.0,b=0.0,c=0.0,d=0.0;
cin>>a>>b>>c>>d;
for(int k=-10000;k -
02009-10-29 18:34:03@
数据弱,应该出个a=0的情况