Title Link: http://acm.nyist.net/JudgeOnline/problem.php?pid=529
Because this problem slot too many, so did not resist ...
Slot Time:
See this problem through the rate of surprisingly high and then happy to come in want to water off ... but ...
The beginning of the mad Baidu to find a discussion area also completely do not understand test instructions Ah,
Fortunately later through these fragmentary clues brain the following test instructions,
Can AC but not very sure 484 the original meaning, hope to everyone helpful (say this will not help Ah ^_^).
Topic Meaning:
The number of digits (0 to 1, or 1 to 0) of the binary of x is changed to x+1 the decimal x, and only one of the binary x is allowed at a time, and the minimum number of times is required. haha!
Problem Solving Ideas:
By manual draft method plus the finger and fast mental arithmetic on the paper (this is the Divine Horse algorithm 0.0) calculated the result of a pass, the process is simply described as follows
1 (0001)->0011->0010->2 (0010) = Change 2 times
2 (0010)->0011->3 (0011) = Change 1
3 (0011)->0111->0110->0100->4 (0100) = Change 3
4 (0100)->0101->5 (0101) = Change 1
5 (0101)->0111->0110->6 (0110) = Change 2
Haha, get the rule: X binary number from 1 start from right to left number the first 0 position is a few need to change a few times.
(PS: So long the principle even feel a bit like said and did not say the same)
(Rule principle: The minimum number of changes is X of the binary plus 1, including the position of the change in the rounding, the binary plus 1 of the change in the carry-out to stop the binary number of x from right to left number the first 0 of the position.)
I'm going to finally be able to write the code. Recently comic read more, unknowingly vomit so many slots, so rare can not be wasted to write to the blog, haha haha
For me this simple boy is still to a paragraph of my easy to walk the violence of the law bar, overtime what we do not, Haha, (after the AC said, hey)
1#include <iostream>2 using namespacestd;3 intMain () {4 intT, x, N;5CIN >>T;6 while(t--) {7CIN >>x;8n =0;9 inty = x percent2;Ten Do { Oney = x percent2; AX/=2; -n++; -} while(Y! =0); thecout << N <<Endl; - } -}
< code implementation > click to expand
started written in: 2016.9.9----zhi Yin
Nyoj: Title 529 Flip