讨论 / 2,4点过不了,求破
huhang1996 2013-10-06 20:41:00
点我顶贴 收藏 删除
#include<iostream>

#include<fstream>

#include <iomanip>

using namespace std;

ifstream fin("fc.in");

ofstream fout("fc.out");

int a,b,c,d;

double sol[4];

int num;

double fc(int q,int w,int e,int r,double x)

{

return(q*x*x*x+w*x*x+e*x+r);

}

int main()

{

double k1,k2;

cin>>a>>b>>c>>d;

for(double i=-10000;i<=10000;i++)

if(num<3)

{

k1=i/100;

k2=(i+1)/100;

if(((fc(a,b,c,d,k1)*fc(a,b,c,d,k2))<0)||(fc(a,b,c,d,k1)==0))

{

num++;

sol[num]=k1;

}

}

for(int i=1;i<=num;i++)

cout<<fixed<<setprecision(2)<<sol[i]<<" ";

return 0;

}

#1 nyl@2013-10-06 20:41:00
回复 删除
a, b, c, d不一定是整数。。。。被坑惨了。。。
#2 g++@2016-03-12 16:55:47
回复 删除
assign(input,'y.in');reset(input);

assign(output,'y.out');rewrite(output);

readln(a,b,c,d);

f:=false;

for i:=-100 to 100 do

begin

ans:=101.01;

q1:=i*i*i*a+i*i*b+i*c+d;

q2:=(i+1)*(i+1)*(i+1)*a+(i+1)*(i+1)*b+(i+1)*c+d;

if q1*q2<0 then

begin

h:=i;

t:=i+1;

ans:=(H+t)/2;

while (abs(fun(h)- fun(ans))>0.0001) or (abs(fun(t)-fun(ans))>0.0001) do

begin

if fun(ans)*fun(h)<0 then

begin

t:=ans;

ans:=(H+t)/2;

end;

if fun(ans)*fun(t)<0 then

begin

h:=ans;

ans:=(H+t)/2;

end;

end;

end;

if q1=0 then

ans:=i;

if (ans<=100) and (ans>=-100) then

if f then write(' ',ans:0:2)

else

begin

f:=true;

write(ans:0:2);

end;

end;

writeln;

end.

查看更多回复
提交回复