programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Bus ride

Kaspersky Ukshini
Ranch Hand
Posts: 122
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
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
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
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:

Kaspersky Ukshini
Ranch Hand
Posts: 122
Maximum cost would probably be:

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

Kaspersky Ukshini
Ranch Hand
Posts: 122
• 1
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