UVA 575 Skew Binary (water)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.