|
|
вернуться в форумAny hint, please? Послано Li Yi 6 окт 2001 13:46 Re: Any hint, please? >I think only search is okey. Re: Any hint, please? >I think only search is okey. ur solution is not good. the better way is use remainder(mod) Re: Any hint, please? Послано Kit 12 апр 2005 00:12 I wanna offer my solution (I think, author had in view same method). Arrange digits of the number in a such way: (non-zero digits in arbitrary order)1234(all zeroes). Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it). Edited by author 12.04.2005 01:20 Re: Any hint, please? Is anybody willing to tell me why it works? Re: Any hint, please? I wanna offer my solution (I think, author had in view same method). Arrange digits of the number in a such way: (non-zero digits in arbitrary order)1234(all zeroes). Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it). Edited by author 12.04.2005 01:20 No sorting, just "cutting" one : 1,2,3,4 from input number; selecting zeros and constructing "possible answer" :) Re: Any hint, please? Послано Madhav 23 сен 2010 02:45 cant we use dynamic programming.It is a O(2^numberofdigits) algorithm. Can any one tell me why the other solution works? Re: Any hint, please? @Nickolas > Is anybody willing to tell me why it works? You can write a sample program and see, that permutations of 1234 produce all possible remainders in division by 7. So <some non-zero numbers><permutation on 1234><zeros> always fits. Re: Any hint, please? Just use random_shuffle. |
|
|