• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bus ride  RSS feed

 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This next problem I have to solve involves Busses lol.

In a buss station, there are N adults, and M kids.
The price for one ticket is 100 (whatever that is dollars/euros). If an adult wants to travel with K kids, he will have to pay ONE ticket for himself, and k-1 tickets for the kids (the ride for ONE kid is free). There is also a rule, that NO kid can ride without an adult.

I have to calculate the Maximum and the Minimum amount of money for which all the passengers would have to pay in order to ride.

The number of adults and kids is given by input, I just have to calculate both cases...

I have NO idea how to solve this, or with what to solve this.... 2days left for the exam, and these type of exercies are very important, cause there will be one like this for sure!
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take an easy example.

If there's 5 adults and 5 kids, what's the minimum/maximum for that combination? You might need a pencil.
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the minimum would be if all the adults take one kid, so all have 1, and they don't pay for the kid at all.
The maxium would be, if one adult pays for all the kids...

is that correct?
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems right to me. If you try it with different numbers, you'll see a pattern.

So there's two mathematical equations you can come up with:

minCost = (numOfAdults)(100) + ?
maxCost = (numOfAdults)(100) + ?
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maximum cost would probably be:

maxCost = (numOfAdults)(100) + (numOfKids-1)(100)

but the minimum, I guess we first check
1. if numOfAdults and numOfKids are equal, in that case it would just be (numOfAdults)(100),
2. if numOfAdults is bigger than numOfKids, in that case it would again be (numOfAdults)(100)
3. if numOfAdults is smaller than numOfKids, in this case I believe I should divide the num of kids/adults, and then I don't know lol... if it's a whole number, okay... (for example if 5 adults, 10 kids = 2kids per adult... but if we have 11/2 for example?

P.S; what do you suggest I solve it with?
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. if numOfAdults and numOfKids are equal, in that case it would just be (numOfAdults)(100),
2. if numOfAdults is bigger than numOfKids, in that case it would again be (numOfAdults)(100)
3. if numOfAdults is smaller than numOfKids, in this case I believe I should divide the num of kids/adults, and then I don't know lol... if it's a whole number, okay... (for example if 5 adults, 10 kids = 2kids per adult... but if we have 11/2 for example?

Each adult only gets one free kid division is unnecessary. It's the same cost at 5 adults and 11 kids if each adult gets two/three as if each one gets one and the last guy gets stuck with the rest. Right?

I think this might be closer:

maximumFreeChildren = ??? number of adults ???
numberOfPaidChildren = totalChildren - maximumFreeChildren
minCost = (numOfAdults)(100) + numberOfPaidChildren(100)
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly!
I managed to make it work.... perfect!
I just checked if the num of kids is bigger than the num of adults, if yes, then I did kids-adults=gave me the number of kids which should pay *100...

THank youuuuuuu!! Make sure to check my next topic lol :p
Seriously, thank you for making it easier for me to prepare for the exam, I really appreciate it guys
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!