Test instructions: According to this binary algorithm, for example, give you a left-hand, ask to launch the right type. (In fact, the right-hand type is a decimal number, which is converted into a special binary number according to this rounding method.) )
Idea: Observing the conversion feature is somewhat similar to binary, but it's also minus one in the back. For example, 25-1, 24-1 ... 21-1. What if we don't lose 1? If you look at it from the left, you'll have more (25-1) *1+1* (23-1) +2* (22-1). That is, we can first multiply the 10120 from right to left by multiplying 21 22 23 24 25 and subtracting 10120 to produce the result.
Of course, you can also follow the above formula to honestly calculate.
#include <bits/stdc++.h>#defineLL Long Longusing namespacestd;intMain () {//freopen ("Input.txt", "R", stdin); Chars[ -]; while(~SCANF ("%s", s)) {LL ans=0, fun=2; intlen=strlen (s); if(len==1&&s[0]=='0') Break; Reverse (s,s+Len); for(intI=0; i<len; i++,fun+=Fun ) ans+ = (s[i]-'0')*Fun ; for(intI=0; i<len; i++) ans-=s[i]-'0'; cout<<ans<<Endl; } return 0;}View Code
UVA 575 Skew Binary (water)