Post
by **vardiar** » Tue Oct 04, 2005 5:53 pm

what about this one

//the record 43 WA!!!!!

#include <string>

#include <vector>

#include <cstdio>

#include <cmath>

#include <algorithm>

#include <iostream>

#include <sstream>

using namespace std;

long double f1(long double p,long double q,long double r,long double s,long double t

,long double u,long double x)

{

return ( p*exp(-1*x)+ q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u );

}

/*long double f(long double p,long double q,long double r,long double s,long double t

,long double u,long double a

,long double b)

{

return (b-(((b-a)*f1(p,q,r,s,t,u,b))/(f1(p,q,r,s,t,u,b)-f1(p,q,r,s,t,u,a))));

}*/

void main()

{

int p1,q1,r1,s1,t1,u1;

long double a=0,b=1,c=0;

int g=0;

while(cin>>p1>>q1>>r1>>s1>>t1>>u1)

{

g=0;

long double p=p1,q=q1,r=r1,s=s1,t=t1,u=u1;

a=0;

b=1;

c=0;

long double f1a,f1b,f1c,c1=999999999;

f1a=f1(p,q,r,s,t,u,a);

f1b=f1(p,q,r,s,t,u,b);

while(1)

{

//f1a=f1(p,q,r,s,t,u,a);

//f1b=f1(p,q,r,s,t,u,b);

if(f1a*f1b>0)

{

cout<<"No solution"<<endl;

break;

}

if(f1a==0)

{

//a+=0.005;

printf("%.4f\n",a);

g=0;

break;

}

if(f1b==0)

{

//b+=0.005;

printf("%.4f\n",b);

g=0;

break;

}

//c=f(p,q,r,s,t,u,a,b);

//c1=c;

c=(b+a)/2;

f1c=f1(p,q,r,s,t,u,c);

if(f1a*f1c<0)

{

b=c;

f1b=f1c;

}

if(f1b*f1c<0)

{

a=c;

f1a=f1c;

}

//f1c=f1(p,q,r,s,t,u,c);

if(f1c==0 ||abs(f1c-c1)<0.00001)

{

//c+=0.005;

printf("%.4f\n",c);

g=0;

break;

}

c1=f1c;

g++;

}

}

}[/code]