Page 1 of 5

### 10341 - Solve It

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

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

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]

### Value of e

Posted: Sat Aug 03, 2002 5:17 pm
Can't you write e=exp(1);

### Thanks..^^

Posted: Sat Aug 03, 2002 6:18 pm
I modified something..

So, I recieve Accepted..

Thanks~*

Posted: Tue Aug 20, 2002 2:33 pm
Could anyone tell me, what could be wrong with this code ? I got WA ....

Code: Select all

``cutted off spoiler ...``

Posted: Tue Aug 20, 2002 3:49 pm
Ok, your value is not precise enough, finally I found it. Try with step*=0.9 and min = f(1), max = f(0) because the function is monotonic decreasing.

### 10341 I have send it for many times. But it's still "W

Posted: Wed Aug 28, 2002 5:30 pm
{ @BEGIN_OF_SOURCE_CODE }
{ @JUDGE_ID: 18459CN 10341 PASCAL "EA" }
program ProbF(input, output);
const
ep = 1e-14;

var
p, q, r, s, t, u: integer;

function f(x: extended): extended;
begin
f := p * exp(-x) + q * sin(x) + r * cos(x) + s * sin(x) / cos(x) + t * sqr(x) + u;
end;

function f_(x: extended): extended;
begin
f_ := - p * exp(-x) + q * cos(x) - r * sin(x) + s / sqr(cos(x)) + 2 * t * x;
end;

procedure solve;
var
x0, x1: extended;
i: integer;
begin
if(p = 0)and(q = 0)and(r = 0)and
(s = 0)and(t = 0)and(u <> 0)then
begin
writeln(output, 'No solution');
exit;
end;
x1 := 0;
while(abs(f(x1)) < ep)or(abs(f_(x1)) < ep)do x1 := x1 + 1;
for i := 1 to 5000 do
begin
x0 := x1;
{if abs(f_(x0)) < ep then
begin
writeln(output, 'No solution');
exit;
end;}
x1 := x0 - f(x0) / f_(x0);
if abs(x1 - x0) < ep then break;
end;
if abs(f(x1)) < ep then
writeln(output, x1:0:4)
else
writeln(output, 'No solution');
end;

begin
while not eof(input) do
begin
readln(input, p, q, r, s, t, u);
solve;
end;
end.
{ @END_OF_SOURCE_CODE }

Posted: Thu Aug 29, 2002 12:37 am
TRY THE CONCEPT OF BINARY SEARCH.

### [10341] - WA ?

Posted: Thu Sep 05, 2002 8:07 am
Why I get WA ??? For the test case it works ...

My code here:

[c]/* @JUDGE_ID: 13213RX 10341 C "<a href="http://cpu.ucpel.tche.br/">Clube de Programa

Posted: Tue Jun 17, 2003 10:48 am
Excuse me.

Is the given function strictly increasing/decreasing?

Note: "the given function" refers to
f(x) = p*e^(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x^2 + u

Posted: Tue Jun 17, 2003 11:05 am
Is the given function strictly increasing/decreasing?
I have never plotted it, but considering all the trigonometric functions I would say no, it is definitely not strictly increasing / decreasing. However, you can be sure that the function has at most one root in between 0 and 1 inclusive.

Best regards

Posted: Tue Jun 17, 2003 11:47 am
Well...

I think that Bisection Method can be used iff the function is strictly increasing/decreasing within the limits...
Or am I wrong??

Posted: Tue Jun 17, 2003 11:51 am
Observer wrote:Well...

I think that Bisection Method can be used iff the function is strictly increasing/decreasing within the limits...
Or am I wrong??
OK. I see that I'm wrong. It should be:
Bisection Method can be used iff f(upper) and f(lower) are of opposite signs...

Anyway, I've just got an ACC!!!!!!! Thx everyone!!!

Posted: Wed Jul 02, 2003 4:24 pm
Please, help! What wrong with this code?

Code: Select all

``````#include <iostream.h>
#include <math.h>
#include <stdio.h>

int p,q,r,s,t,u;
double a, b, c;

double f(double x)
{
return p/exp(x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u;
}

int main() {

while ((cin >> p >> q >> r >> s >> t >> u) != NULL) {

a = 0.0; b = 1.0;

if (f(b) > 0 || f(a) < 0) {
printf("No solution\n");
continue;
}

while (b - a >= 0.00001) {

if (f(a) == 0) {
printf("%.4lf\n", a);
break;
}

if (f(b) == 0) {
printf("%.4lf\n", b);
break;
}

c = (a + b) / 2;

if (f(a) * f(c) > 0) a = c; else b = c;

}

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

}

return 0;
}``````

Posted: Tue Jul 15, 2003 10:42 pm
i am not sure about the bugs of your problem but you can check your prgram for the inputs when the answer will be 0.0000 or 1.0000.

Posted: Wed Jul 16, 2003 2:59 pm
actually nr or bisection method need not know the fn is either inc or dec.
if you check two limits for which the funtion gives values of opposite sign, you can be sure that there is a sol between the limits.