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. IOS - 唯一标识符的获得和更新

    苹果公司不可能让其他人获得个人终端的唯一标识符,所以一个终端给另一个终端发送消息,必须经过苹果的APNS(Apple Push Notification Service)....而且苹果为了防止苹果用 ...

  2. ios安装cocoaPods

    1. 安装 a. 查看源 i.   gem sources -l b. 删除源 i.   sudo gem sources -r https://rubygems.org/ c. 设置源 i.   s ...

  3. Android 在 manifest 文件里增加 versionCode,运行后版本并没有随之增加

    现象:从 git 上拉下来的代码中 versionCode 是8,versionName 是1.0.7但运行后的版本仍然是1.0.6 原因:全文搜索1.0.6之后发现在 bin 目录下也有一个 man ...

  4. 测试Open Live writer

    这个东西究竟是怎么用的啊,看起来好高端的样子...

  5. myaql常用函数

    一.数学函数 abs(x)   返回x的绝对值 bin(x)   返回x的二进制(oct返回八进制,hex返回十六进制) ceiling(x)   返回大于x的最小整数值 exp(x)   返回值e( ...

  6. Mex文件在VS2010中调试方法

    http://www.cnblogs.com/lukylu/p/4042306.html matlab里面无法单步调试mex函数,故需转到VS上面调试,这里采用VS2010. 参考网上很多人写的方法但 ...

  7. RabbitMQ驱动简单例子

    using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Collections.Generic; ...

  8. Git撤销提交和修改相关操作

    团队开发中经常遇到错误删除文件,错误提交等情况,那么使用Git该如何正确的进行撤销和恢复呢? 一.增补提交 git commit –C HEAD –a --amend -C表示复用指定提交的提交留言, ...

  9. Newtonsoft.Json(Json.Net)学习笔记(转)

    概述 Newtonsoft.Json,一款.NET中开源的Json序列化和反序列化类库,通过Nuget获取.(查看原文) 下面是Json序列化和反序列化的简单封装: /// <summary&g ...

  10. VC++中字符串编码的转换

    在以前VC++6.0中默认的字符集是多字节字符集(MBCS:Multi-Byte Character Set),而VS2005及以后默认的字符集是Unicode,这样导致以前在VC6.0中非常简单实用 ...