You are not logged in. Please login at www.codechef.com to post your questions!

×

[closed] 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.

asked 21 Apr '14, 00:18

damn_me's gravatar image

3★damn_me
2.6k21336
accept rate: 24%

closed 21 Apr '14, 00:34

betlista's gravatar image

3★betlista ♦♦
16.9k49115225

How are you planning to compute the integral?

(21 Apr '14, 00:23) wittyceaser2★
1

@damn_me, damn you it was correct :)

(21 Apr '14, 00:26) garakchy1★
2

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..

(21 Apr '14, 00:27) damn_me3★
1

@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..!! :\

(21 Apr '14, 00:29) damn_me3★

@damn_me, damn me i forgot to mention that i was joking ;P

(21 Apr '14, 00:30) garakchy1★
1

@garakchy I'll not mind that. Programmers are meant to learn, doesn't matter which way. :) 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).

(21 Apr '14, 00:34) damn_me3★
1

@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.

(21 Apr '14, 00:36) damn_me3★

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

(21 Apr '14, 00:42) garakchy1★

@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. :P however, did u see the code..??

(21 Apr '14, 00:44) damn_me3★

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

(21 Apr '14, 00:56) garakchy1★

@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.

(21 Apr '14, 01:00) damn_me3★

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

(21 Apr '14, 01:04) garakchy1★
showing 5 of 12 show all

The question has been closed for the following reason "Should be discussed on editorial page - see CoC" by betlista 21 Apr '14, 00:34

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,916
×105

question asked: 21 Apr '14, 00:18

question was seen: 2,059 times

last updated: 21 Apr '14, 01:04