C - Base -2 Number


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

Given an integer NN, find the base −2−2 representation of NN.

Here, SS is the base −2−2 representation of NN when the following are all satisfied:

  • SS is a string consisting of 0 and 1.
  • Unless S=S= 0, the initial character of SS is 1.
  • Let S=SkSk−1...S0S=SkSk−1...S0, then S0×(−2)0+S1×(−2)1+...+Sk×(−2)k=NS0×(−2)0+S1×(−2)1+...+Sk×(−2)k=N.

It can be proved that, for any integer MM, the base −2−2 representation of MM is uniquely determined.

Constraints

  • Every value in input is integer.
  • −109≤N≤109−109≤N≤109

Input

Input is given from Standard Input in the following format:N

Output

Print the base −2 representation of N.


Sample Input 1 Copy

Copy

-9

Sample Output 1 Copy

Copy

1011

As (−2)0+(−2)1+(−2)3=1+(−2)+(−8)=−9(−2)0+(−2)1+(−2)3=1+(−2)+(−8)=−9, 1011 is the base −2 representation of −9.


Sample Input 2 Copy

Copy

123456789

Sample Output 2 Copy

Copy

11000101011001101110100010101

Sample Input 3 Copy

Copy

0

Sample Output 3 Copy

Copy

0

题意

输入一个数,求该数的负二进制数

先记下来,代码不是太理解,明天慢慢看

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int main(int argc, char const *argv[])
{
int n;
cin>>n;
if(n==1||n==0)
{
cout<<n<<endl;
return 0;
}
int k=0;
while(n)
{
int m=n;
a[k++]=abs(n)%2;
n/=-2;
if(m<0&&abs(m)%2)
n++;
}
for(int i=k-1;i>=0;i--)
cout<<a[i];
cout<<endl;
return 0;
}

Atcode ABC105-C:Base -2 Number的更多相关文章

  1. C# 中的关键字之:base、this 【转】

                                                                                 C# 中的关键字之:base.this. ba ...

  2. 动手写个数字输入框1:input[type=number]的遗憾

    前言  最近在用Polymer封装纯数字的输入框,开发过程中发现不少坑,也有很多值得研究的地方.本系列打算分4篇来叙述这段可歌可泣的踩坑经历: <动手写个数字输入框1:input[type=nu ...

  3. xtrabackup备份MySQL报错:InnoDB: Error number 24 means 'Too many open files'

    xtrabackup备份MySQL报错:InnoDB: Error number 24 means 'Too many open files' 1.使用xtrabackup备份MySQL时出现如下报错 ...

  4. 配置iOS项目的设备系统目标设置:Base SDK和Deployment Target

    配置iOS项目的设备系统目标设置:Base SDK和Deployment Target Xcode为开发者提供了两个可配置的设置:第一个是Base SDK,第二个是iOS的Deployment Tar ...

  5. 第193天:js---Math+Error+Number+Object总结

    一.Math 随机选取 //随机选取 function getRandom (begin,end){ return Math.floor(Math.random()*(end-begin))+begi ...

  6. 【POI】导出xls文件报错:The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook

    使用POI导出xls文件,由于数据过多,导致导出xls报错如下: The maximum number of cell styles was exceeded. You can define up t ...

  7. oracle创建jobs定时任务报错:PLS-00306: wrong number or types of arguments in call to 'JOB'

    原脚本: begin  sys.dbms_job.submit(job => job,                      what => 'xxx;',              ...

  8. EF:oracle的number类型映射为C#的boolean类型

    一开始用下面的方法映射, Property(p => p.IsFixed).HasColumnName("IS_FIXED").HasColumnType("num ...

  9. JS魔法堂:再识Number type

    Brief 本来只打算理解JS中0.1 + 0.2 == 0.30000000000000004的原因,但发现自己对计算机的数字表示和运算十分陌生,于是只好恶补一下.以下是恶补后的成果: 基础野:细说 ...

随机推荐

  1. linux nginx 添加到全局变量中(环境变量)

    ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/ /usr/local/bin/就是环境变量目录

  2. NiXi.DAY06东软实训.:面向对象思想~抽象~static~final~构造方法及其重载

    本章技能目标: 使用类图描述设计 掌握面向对象设计的基本步骤 掌握类和对象的概念 掌握构造方法及其重载 掌握封装的概念及其使用 本章单词: class:类 object:对象 static: fina ...

  3. 将自己的域名解析跳转到博客主页(GitHub中的gitpage跳转)

    最近突然迷上了博客,突然又突发奇想,将自己几个月前买的现在限制的域名拿来跳转到自己的csdn博客.经过一番研究,总结---- 把自己的购买的域名(比如我买的circleyuan.top)跳转到CSDN ...

  4. Azulão--青鸟--IPA--巴西葡萄牙语

    这是巴西很有名的民谣.

  5. 什么是RUP

    Rational统一过程(Rational  Unified  Process,RUP)是由Rational软件公司推出的一种完整且完美的软件过程. RUP总结了经过多年商业化验证的6条最有效的软件开 ...

  6. android 获取Asset中Properties文件配置的键值对

    1 获取 AssetManager AssetManager assetManager = context.getApplicationContext().getAssets(); 2 获取流 Str ...

  7. js重写trim()方法

    最近项目中出现去空格的需求,我本地是IE11,使用trim()函数的时候,是无法识别的.因此重写String的trim()方法. 1.要求 可以去除首位全角,半角空格. 2.对   能去除所有 Str ...

  8. MySql:触发器

    触发器 一.触发器的定义: 触发器是个特殊的存储过程,不同的是,执行存储过程要使用CALL语句来调用,而触发器的执行不需要使用CALL语句来调用,也不需要手工启动,只要当一个预定的事件发生时,就会被M ...

  9. python 递归函数操作方法

    .递归 是指函数/过程/子程序在运行过程序中直接或间接调用自身而产生的重入现象.在计算机编程里,递归指的是一个过程:函数不断引用自身,直到引用的对象已知.使用递归解决问题,思路清晰,代码少.但是在主流 ...

  10. java学习笔记5(方法)

    方法: 1.如何创建方法 修饰符   返回值类型  方法名(参数){被封装的代码段} 2.方法的定义和使用的注意事项: a:方法不能定义在另一个方法里面: b:方法 名字和方法的参数列表,定义和调用时 ...