problem 22

Back to Problem Solutions forum

Andris Laduzans     2019-03-06 20:31:13

Im strugling to do task #22 i looked up some math theory on combined work and by my calculations i did everything corectly but the results are far from what i was expecting, here are the console results.

3
 seconds for one page 1st
5
 seconds for one page 2nd
4
 all pages
12 how fast 1st print all
20 how fast 2nd print all
0.333333 this portion 1st print in 1 sec
0.2 this portion 2nd print in 1 sec
0.533333 this portion print together in 1 sec
7.5 how fast will print all together

Process returned 0 (0x0)   execution time : 5.559 s
Press any key to continue.

my result is 7.5 instead of 9 and im not even sure how can you get to 9? also i red similar post and the tip given there. It said both printers does not work all the time together e.g. they cannot divide same page. But i still dont understand how am i supposed to implement that into my solution. pls, someone? im completely clueless, maybe someone has decent math theory article about this kind of problem? anything.

Quandray     2019-03-06 20:41:20
User avatar

Your answer of 7.5 makes no sense at all. The slow printer takes 5 seconds to print a page. The fast printer takes 3 seconds to print a page. The answer can only be a whole number of seconds. If you print 1 of the 4 pages on the slow printer, it will take 5 seconds. While that is happening, printing the remaining 3 pages on the fast printer, will take 9 seconds. So, total time overall is 9 seconds, and it can't be done quicker.

Rodion (admin)     2019-03-06 20:54:13
User avatar

Hi Andris!

Your calculations are a bit queer. If 1 page is printed in integer number of seconds on any of printers (3 or 5) then 4 pages could not be printed in non-integer amount of seconds :)

Imagine you want to print only 1 page. By your calculations 2 seconds should be enough, as 1st printer will do 0.66 and the 2nd will print 0.4 of the page. But we can't split the page between them, of course.

Let's regard this case in details:

  • we can print 4 pages on 1st printer (12 sec) while 2nd does nothing - totalling to 12 sec
  • we can print 3 pages on 1st printer (9 sec) and 1 page on 2nd (printing for 5 sec, sleeping remaining 4) - total 9
  • we can print 2 pages on 1st printer (6 sec) and 2 pages on 2nd (10 sec) - totalling to 10 sec
  • we can print 1 page on 1st printer (3 sec) and 3 pages on 2nd (15 sec) - obviously it is even worse
  • we can print all 4 pages on 2nd printer (20 sec) - slowest of all.

So the best case is with 9 seconds, right?

If you feel that right now some problem is yet bit too hard for you, just skip it for now and get practice with others - you can always return to the skipped problem in a day or week, it often helps!

Andris Laduzans     2019-03-07 07:06:18

Okay i see now. But going page by page will take tramedeous time amount. I guess i have to divide them pages in some proportions for each printer in later test cases. but how do i know the proportions? I suppose i can look up proportion theory in math...daaaamn i wish i was paying more attention in math classes when i was younger :D

Anyway thank you, both of you.

Rodion (admin)     2019-03-07 07:23:14
User avatar

See, your answer seems to be not far from correct. That means that your "proportions" are almost correct. Only need some fix to care of integer amount of pages.

Andris Laduzans     2019-03-07 20:08:40

completed! tho i cannot really explain the calculations behind my answers. :( for some reasons it all came down to how i round one of my calculations. if i round up "ceil"(in c++) i end up with some errors but when i use regular "round" those errors clear but then some others appear. so i figured i can calculate both results for all test cases and just print out the smallest. But i still dont really understand when was i supposed to round up and when not to... anyway im getting the correct results, took it almost 2 days, thank you so much for your help.

Rodion (admin)     2019-03-07 21:32:04
User avatar

congrats!

so i figured i can calculate both results for all test cases and just print out the smallest

exactly what was supposed! at least I myself don't know any way other than checking few solutions "around" fractional :)

Please login and solve 5 problems to be able to post at forum