Was my approach correct for Travelling Chef problem?

Although I wasn’t able to code correctly this question http://www.codechef.com/COOK45/problems/TCP,
but was my following approach correct for solving:

The distance required as the output is basically the integral of the V(t) equation given under the limits (T,0). For computing this, we need to have the value of A,B,C,D. We have four values satisfying the V(t) equation and 4 solutions and three variables are enough for computing the coefficients.

For finding A,B,C,D I used matrix multiplication. For first three values i framed a 3X3 matrix A and B as the corresponding values of v(t). Then a,b,c can be found as matrix X,

X=A^(-1)B 

i.e. X= (Ainverse)*B.

PS: I didn’t use 4*4 matrix to avoid long calculations for finding the inverse. Using values of a,b,c we can find d and thus the distance.

2 Likes

How are you planning to compute the integral?

@damn_me, damn you it was correct :slight_smile:

1 Like

I have values of a,b,c,d and the given time for which I just need to put the limits in it. The integral will be of the sort:

[A(t^4)/4 + B(t^3)/3 + C(t^2)/2 + Dt] and limits will be the input time T and 0. And we can thus find it easily…

2 Likes

@garakchy But i coded this just once and ran which gave wrong answer on ideone itself, so just left it. Don’t know the mistake in it…!! :\

1 Like

@damn_me, damn me i forgot to mention that i was joking :stuck_out_tongue_winking_eye:

@garakchy I’ll not mind that. Programmers are meant to learn, doesn’t matter which way. :slight_smile: This code: http://ideone.com/5Q4cuK although is a very rough one and can be optimized even (just for framing the logic and telling what i mean exactly).

1 Like

@garacky Will be easier to understand (in case you see) if you know the way of computing inverse of a 3*3 matrix. Let me know in case u wanna see that.

1 Like

@damn_me, i struggled to find acceleration, distance, physics topics, etc. and could not find any formula to calculate total distance.

@garakchy The only physics involved in this was the distance is the area under the velocity-time graoh which can be calculated by computing the integral. :stuck_out_tongue: however, did u see the code…??

@damn_me, i think “time” in your code collides with time in c++: http://www.cplusplus.com/reference/ctime/time/

@garakchy but I have declared it as an int and even i think I have used such int time; previously also. Or may be that is the only(or probably I should say)reason.

@damn_me, im not sure bro, try by changing “time” to “whatsoever” you think that doesnt collide with c++ parameters