http://codeforces.net/contest/460/submission/34483323
Above is the Link for my solution to the 'Vasya and socks' problem please clarify me where i am going wrong in my algorithm.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
http://codeforces.net/contest/460/submission/34483323
Above is the Link for my solution to the 'Vasya and socks' problem please clarify me where i am going wrong in my algorithm.
Название |
---|
http://codeforces.net/contest/460/submission/34495501
Can you explain me the difference between your code and my code I am beginner so please bear with me
Consider a simple example n=7 m=2 . Lets first calculate correct answer so first n=7. It means the days {1,2,3,4,5,6,7} Here we can buy a pair of socks on second days so we will buy on 2,4,6 . Meaning 3 new pair of socks now the set is {1,2,3,4,5,6,7,8,9,10}. Now we can buy a pair of socks on 8 and 10 . meaning 2 new pair of socks now the set will be {1,2,3,4,5,6,7,8,9,10,11,12} . Now you can buy a pair of socks 12th day. So the set finally becomes {1,2,3,4,5,6,7,8,9,10,11,12,13}. so the answer is 13 where as your answer is 11.
Now lets see what you do in your code . n=7 m=2 result=n days=n 1 iteration result=result/m // result becomes 7/2=3 days=days+result // result becomes 10 result is still greater than 0 2 iteration result=result/m // result becomes 3/2=1 days=days+result // result becomes 11 result is still greater than 0 3 iteration result=result/m // result becomes 1/2=0 days=days+result // result becomes 11 result is 0 so your answer becomes 11 Lets see what you are adding 7/2 + 3/2 + 1/2 = 3+1+0=4 what should have been done was 7/2 + 3/2 + 1/2=(7+3+1)/2=(11)/2=5 so the answer becomes days=7+5=12 and you can buy one more on 12th day. so answer is 13. What I mean is you have to consider modulo operation as well. http://codeforces.net/contest/460/submission/34511057