|
|
back to boardc++ Accepted answer(efficient and simple to understand)+explanation [code deleted by moderator] You are interested in the number of sides, not steaks as total. First you calculate number of sides, then you calculate the remainder between it and the maximum number of steaks that can be cooked in 1 minute. If the remainder is bigger than 1(not equal, if equal you will get wrong answer ex: 7 and 4 yields answer 3 with actually is 4) then you write the number of sides divided by the maximum number(of sides) in the pan plus the extra that remains. Else you do the same without adding the extra. If k>n, then the maximum is 2 minutes(1 minute for each side) because all steaks fit in the pan. It's a simple and quick solution. Some examples: 1. 4 steaks and maximum 3 in a pan. You have 8 sides and a maximum of 3 in a pan. 8%3=1, that means that you have 2 sides extra. Answer is 8/3 + 1 =3 2. 7 steaks and maximum 4 in a pan. You have 14 sides and maximum 4 in a pan. 14%4=2, that is why you need to put 2*n%k>=1 and not 2*n%n==1. The answer is 14%4 + 1 =3+1=4 I hope that it helped! Edited by moderator 21.07.2014 01:04 Re: c++ Accepted answer(efficient and simple to understand)+explanation Posted by mhg 7 Jul 2014 17:57 thanks. Edited by author 07.07.2014 18:01 Re: c++ Accepted answer(efficient and simple to understand)+explanation Posted by Gefest 19 Oct 2014 06:37 Thanks, realy helped. |
|
|