Skew Binary
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 10676   Accepted: 6807

Description

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

81307(10) = 8 * 10^4 + 1 * 10 ^3 + 3 * 10^2 + 0 * 10^1 + 7 * 10^0 

= 80000 + 1000 + 300 + 0 + 7 

= 81307. 



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



10011(2) = 1 * 2^4 + 0 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 

= 16 + 0 + 0 + 2 + 1 

= 19. 



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



10120(skew) = 1 * (2^5-1) + 0 * (2^4-1) + 1 * (2^3-1) + 2 * (2^2-1) + 0 * (2^1-1) 

= 31 + 0 + 7 + 6 + 0 

= 44. 



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 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

10120
200000000000000000000000000000
10
1000000000000000000000000000000
11
100
11111000001110000101101102000
0

Sample Output

44
2147483646
3
2147483647
4
7
1041110737

大水题。

代码:

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; string test; int main()
{
while(cin>>test)
{
if(test=="0")
break; int len = test.length();
int i,k=1,result=0; for(i=len-1;i>=0;i--)
{
result = result+ (int)(test[i]-'0')*(int)(pow((double)2,k)-1);
k++;
}
cout<<result<<endl;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1565:Skew Binary的更多相关文章

  1. UVa 575 Skew Binary 歪斜二进制

    呵呵,这个翻译还是很直白的嘛,大家意会就好. 第一次看到这个高大上题目还是有点小害怕的,还好题没有做过深的文章. 只要按照规则转化成十进制就好了,而且题目本身也说了最大不超过一个int的范围(2^31 ...

  2. 相邻数字的基数不等比:skew数

    2973:Skew数 描述在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1). 每个位上的可能数字是0 或 1,最后面一个非零位可以是2, 例如, 10120(skew) ...

  3. 九度OJ 1129:Skew数 (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:734 解决:548 题目描述: 在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1).  每个位上的可能数字是0 ...

  4. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  5. poj1565---(数论)skew binary

    /*将数字存储在数组中 #math.h strlen(a)=len sum=0 for(i=0;i<len;i++) sum+=a[i]*(pow(2,len-i)-1)*/ #include ...

  6. [线索二叉树] [LeetCode] 不需要栈或者别的辅助空间,完成二叉树的中序遍历。题:Recover Binary Search Tree,Binary Tree Inorder Traversal

    既上篇关于二叉搜索树的文章后,这篇文章介绍一种针对二叉树的新的中序遍历方式,它的特点是不需要递归或者使用栈,而是纯粹使用循环的方式,完成中序遍历. 线索二叉树介绍 首先我们引入“线索二叉树”的概念: ...

  7. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  8. # Leetcode 67:Add Binary(二进制求和)

    Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...

  9. POJ 1565 Skew Binary(简单的问题)

    [简要题意]:第二个是数字系统的代表性的定义.而给了你这个号码系统提示的形式和十进制转换之间的关系.现在给你一些这样的系统.让你把它变成2二进制输出. [分析]:当中 base[k]  =  2^(k ...

随机推荐

  1. yii 框架 – 安全站点和非安全站点的 URL 管理

    在本文中我将描述怎么管理安全站点和非安全站点的 URL 管理. 安全站点的内容使用httpsSSL (安全套接字层) 协议发送,而非安全站点使用http协议.为了描述简单,我们称前者https内容/页 ...

  2. 用C语言写一个Helloworld_实现第一步编译运行

    编写第一个hello world 创建helloworld.c // 程序头文件 #include <stdio.h> // 主入口函数 int main(int arc, char* a ...

  3. css元素隐藏方式

    1.opacity:设置一个元素的透明度 .hide {opacity: 0;} 2.visibility:设置一个元素可见\不可见.hide {visibility: hidden} .hide { ...

  4. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:表示一个危险的操作

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. jqGrid 重新加载数据

    参考:https://blog.csdn.net/u012746051/article/details/52949353 $("#列表区域id").jqGrid('clearGri ...

  6. 华为轮值CEO,富士康却坚持独裁,二者究竟有什么不一样?

    谈到深圳龙华的大企业,人们会很自然地想到华为和富士康,两家公司毗邻,有两个门仅仅隔着一条马路,都是世界500强,对国家,对社区的经济发展有着重要贡献,员工压力最大的时候,也都出现过自杀的情况,一个讲究 ...

  7. input文件类型上传,或者作为参数拼接的时候注意的问题!

    1.ajax请求参数如果为文本类型,直接拼接即可.如果为file类型就需要先获取文件信息 2.获取文件信息: HTML代码: <div class="form-group"& ...

  8. IDEA中如何部署tomcat

    1.添加tomcat 2.添加tomcat所依赖的war包 test009.war包刚开始可能不存在,这个时候需要将maven项目进行打包,然后点击“+”之后就会出现一个和项目名同名的war包,选中就 ...

  9. php 增删改查范例(1)

    主页index.php(含多条件查询): <?php$db = new Mysqli("localhost","root","root" ...

  10. 终于解决ERROR: PHP's 'ldap' extension is not installed/enabled. Please check your MR

    我的系统是centos,php是yum的5.6.40,php-ldap也是yum的5.6.40,配置好ldap后,登录时提示ERROR: PHP's 'ldap' extension is not i ...