### 10341 - Solve It

Posted:

**Sat Aug 03, 2002 1:45 pm**Test set is perfect!!...^^;;

But, I recieve WA...again, again...

Please Help Me..

Where is wrong?

My Algorithm is The Bisection.

[c]

#include<stdio.h>

#include<math.h>

#define Napier 2.71828

int main()

{

int p, q, r, s, t, u;

double start, middle, end;

double start_result, middle_result, end_result;

while(scanf("%d %d %d %d %d %d", &p, &q, &r, &s, &t, &u) > 0)

{

start = 0, middle = 0.5, end = 1;

if(p == 0 && q == 0 && r == 0 && s == 0 && t == 0 && u == 0)

printf("No solution\n");

else

{

while(1)

{

start_result = p*pow(Napier, -1*start) + q*sin(start) + r*cos(start) + s*tan(start) + t*pow(start, 2) + u;

middle_result = p*pow(Napier, -1*middle) + q*sin(middle) + r*cos(middle) + s*tan(middle) + t*pow(middle, 2) + u;

end_result = p*pow(Napier, -1*end) + q*sin(end) + r*cos(end) + s*tan(end) + t*pow(end, 2) + u;

if((middle_result < 0 ? middle_result*-1 : middle_result) <= 0.000000001)

{

printf("%.4lf\n", middle);

break;

}

else if((start_result < 0 && middle_result > 0) || (start_result > 0 && middle_result < 0))

{

end = middle;

middle = (start + end) / 2;

}

else if((end_result < 0 && middle_result > 0) || (end_result > 0 && middle_result < 0))

{

start = middle;

middle = (start + end) / 2;

}

else

{

printf("No solution\n");

break;

}

}

}

}

return 0;

}

[/c]

But, I recieve WA...again, again...

Please Help Me..

Where is wrong?

My Algorithm is The Bisection.

[c]

#include<stdio.h>

#include<math.h>

#define Napier 2.71828

int main()

{

int p, q, r, s, t, u;

double start, middle, end;

double start_result, middle_result, end_result;

while(scanf("%d %d %d %d %d %d", &p, &q, &r, &s, &t, &u) > 0)

{

start = 0, middle = 0.5, end = 1;

if(p == 0 && q == 0 && r == 0 && s == 0 && t == 0 && u == 0)

printf("No solution\n");

else

{

while(1)

{

start_result = p*pow(Napier, -1*start) + q*sin(start) + r*cos(start) + s*tan(start) + t*pow(start, 2) + u;

middle_result = p*pow(Napier, -1*middle) + q*sin(middle) + r*cos(middle) + s*tan(middle) + t*pow(middle, 2) + u;

end_result = p*pow(Napier, -1*end) + q*sin(end) + r*cos(end) + s*tan(end) + t*pow(end, 2) + u;

if((middle_result < 0 ? middle_result*-1 : middle_result) <= 0.000000001)

{

printf("%.4lf\n", middle);

break;

}

else if((start_result < 0 && middle_result > 0) || (start_result > 0 && middle_result < 0))

{

end = middle;

middle = (start + end) / 2;

}

else if((end_result < 0 && middle_result > 0) || (end_result > 0 && middle_result < 0))

{

start = middle;

middle = (start + end) / 2;

}

else

{

printf("No solution\n");

break;

}

}

}

}

return 0;

}

[/c]