Description

Inexperienced in the digital arts, the cows tried to build a calculating engine (yes, it's a cowmpouter) using binary numbers (base 2) but instead built one based on base negative 2! They were quite pleased since numbers expressed in base −2 do not have a sign bit.

You know number bases have place values that start at 1 (base to the 0 power) and proceed right-to-left to base^1, base^2, and so on. In base −2, the place values are 1, −2, 4, −8, 16, −32, ... (reading from right to left). Thus, counting from 1 goes like this: 1, 110, 111, 100, 101, 11010, 11011, 11000, 11001, and so on.

Eerily, negative numbers are also represented with 1's and 0's but no sign. Consider counting from −1 downward: 11, 10, 1101, 1100, 1111, and so on.

Please help the cows convert ordinary decimal integers (range -2,000,000,000..2,000,000,000) to their counterpart representation in base −2.

Input

Line 1: A single integer to be converted to base −2

Output

Line 1: A single integer with no leading zeroes that is the input integer converted to base −2. The value 0 is expressed as 0, with exactly one 0.

Sample Input

-13

Sample Output

110111

Hint

Explanation of the sample:

Reading from right-to-left:

1*1 + 1*-2 + 1*4 + 0*-8 +1*16 + 1*-32 = -13

注:任意的负进制也是如此做法
#include<cstdio>
#include<stack>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll read()//输入外挂
{
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
int n,i;
n=read();
stack<int>s;
if(!n) {printf("0\n");return 0;}//0 需要特判
while(n)
{
for(i=0;;++i)
if((n-i)%2==0) break;
s.push(i);
n=(n-i)/(-2);
}
while(!s.empty()){
printf("%d",s.top());
s.pop();}
printf("\n"); }

  

A - The Moronic Cowmpouter的更多相关文章

  1. POJ3191-The Moronic Cowmpouter

    The Moronic Cowmpouter Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4006   Accepted: ...

  2. POJ 3191 The Moronic Cowmpouter(进制转换)

    题目链接 题意 : 将一个10进制整数转化为-2进制的数. 思路 :如果你将-2进制下的123转化为十进制是1*(-2)^2+2*(-2)^1+3*(-2)^0.所以十进制转化为-2进制就是一个逆过程 ...

  3. The Moronic Cowmpouter(负进位制转换)

    http://poj.org/problem?id=3191 题意:将一个整型的十进制整数转化为-2进制整数. #include <stdio.h> #include <algori ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. Qt 获取cmd运行结果

    http://www.cnblogs.com/gisbeginner/archive/2012/12/08/2809063.html BOOL ExecDosCmd(){ #define EXECDO ...

  2. Qt 扫描进程列表以及获取进程信息

    使用方法: QMap<QString,qint64> app_pid; getAllAppPidList( app_pid ); #include <tlhelp32.h>// ...

  3. September 27th 2016 Week 40th Tuesday

    Friends are lost by calling too often and calling seldom. 交往过密过疏,都会失去朋友. Please mind your own busine ...

  4. August 30th 2016 Week 36th Tuesday

    If you keep on believing, the dreams that you wish will come true. 如果你坚定信念,就能梦想成真. I always believe ...

  5. !gluLookAt与glOrtho 参数解析

    void gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLd ...

  6. NYOJ题目168房间安排

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAOTCAIAAADGwNmiAAAgAElEQVR4nOy9PY7cyLPufTchXwsZu9

  7. bnu24252 海盗分赃

    题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24252 这是四川2012年省赛的一道题,背景:海盗分宝藏.大概题意:给你N种价值的物品,物品有两 ...

  8. poj 2104:K-th Number(划分树,经典题)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 35653   Accepted: 11382 Ca ...

  9. 缓慢变化维 (Slowly changing dimension)

          维度建模的数据仓库中,有一个概念叫Slowly Changing Dimensions,中文一般翻译成"缓慢变化维",经常被简写为SCD.缓慢变化维的提出是因为在现实世 ...

  10. 攻城狮在路上(叁)Linux(三十一)--- vim程序编辑器

    本篇主要介绍vim编辑器的使用方式,具体内容后续补充.