UVA - 575 - Skew Binary (简单数论!)

来源:互联网 发布:高数有没有解题软件 编辑:程序博客网 时间:2024/05/06 01:37

UVA - 575

Skew Binary
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

Submit Status

Description

Download as PDF


  Skew Binary 

When a number is expressed in decimal, the k-th digit represents a multiple of 10k. (Digits are numbered from right to left, where the least significant digit is number 0.) For example, 

\begin{displaymath}81307_{10} = 8 \times 10^4 + 1 \times 10^3 + 3 \times 10^2 + ......mes 10^1 +7 \times 10 0 = 80000 + 1000 + 300 + 0 + 7= 81307.\end{displaymath}

When a number is expressed in binary, the k-th digit represents a multiple of 2k. For example, 

\begin{displaymath}10011_2 = 1 \times 2^4 + 0 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 +1 \times 2^0 = 16 + 0 + 0 + 2 + 1 = 19.\end{displaymath}

In skew binary, the k-th digit represents a multiple of 2k+1 - 1. The only possible digits are 0 and 1, except that the least-significant nonzero digit can be a 2. For example, 

\begin{displaymath}10120_{skew} = 1 \times (2^5 - 1) + 0 \times (2^4-1) + 1 \tim......2 \times (2^2-1) + 0 \times (2^1-1)= 31 + 0 + 7 + 6 + 0 = 44.\end{displaymath}

The first 10 numbers in skew binary are 0, 1, 2, 10, 11, 12, 20, 100, 101, and 102. (Skew binary is useful in some applications because it is possible to add 1 with at most one carry. However, this has nothing to do with the current problem.)

Input 

The input file contains one or more lines, each of which contains an integer n. If n = 0 it signals the end of the input, and otherwise n is a nonnegative integer in skew binary.

Output 

For each number, output the decimal equivalent. The decimal value of n will be at most 2 31 - 1 = 2147483647.

Sample Input 

1012020000000000000000000000000000010100000000000000000000000000000011100111110000011100001011011020000

Sample Output 

44214748364632147483647471041110737



Miguel A. Revilla
1998-03-10

Source


Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics :: Ad Hoc Mathematics Problems :: Base Number Variants
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: Maths - Number Theory
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Ad Hoc Mathematics Problems :: Base Number Variants



AC代码:


#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define LL long longusing namespace std;int main(){char a[40];while(scanf("%s", a)!=EOF){if(strlen(a)==1 && a[0] == '0')break;int len = strlen(a);LL bei=2, ans = 0;for(int i=len-1; i>=0; i--){ans += ( (bei-1) * (a[i]-'0') );bei*=2;}printf("%lld\n", ans);}return 0;} 




1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 王者荣耀号丢了换成了别的号怎么办 微信给空号q币怎么办 qq密码被别人改了怎么办怎么登 qq刚改了密码忘了怎么办 qq密码忘了想改密码怎么办 qq账号和密码都忘了怎么办 我的微信被别人改了密码怎么办 微信被盗密码被改了怎么办 微信被盗了密码都被改了怎么办 微信被别人改密码改手机号了怎么办 微信号手机号码换了密码改了怎么办 电信充值卡的密码刮花了怎么办 qq充了q币不到账怎么办 开通黄钻不支持手机话费开通怎么办 银行卡给红包充值迟迟不到账怎么办 我想用信用卡往微信零钱充钱怎么办 修改密保手机跳过原手机验证怎么办 骏卡有用但是充不进去怎么办 在云南移动上充错话费了怎么办 手机版本太低安装不了支付宝怎么办 手机下载支付宝后找不到了怎么办 王者荣耀充值成功游戏未到账怎么办 银行卡号和密码都忘了怎么办 微信支付密码和银行卡号忘了怎么办 请问5位数的密码忘记了怎么办 苹果手机四位数密码忘记了怎么办 锡山教育app登陆密码忘了怎么办 新商盟手机订烟登录忘记密码怎么办 在qq上修改支付密码忘记怎么办 微信红包支付密码忘了怎么办 qq钱包绑定了别人的银行卡怎么办 用支付宝充手机话费怎么退款怎么办 我有个qq号丢了怎么办 微信红包密码输错了怎么办 qq钱包支付限额付不了款怎么办 电信手机没开流量被扣流量钱怎么办 运动鞋子买大了一码怎么办 淘宝直播间粉丝福利购优惠券怎么办 微信卡包的券不小心删了怎么办 0pp0手机官网手机总跳屏怎么办 很想买一部手机但是舍不得钱怎么办