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. office install problems

    regedit 0000 "00005"或"00002"开头的项 remove all regedit options

  2. kiss prefix paleo,per,pen,pan,para out 1

      1● paleo 2● per 3● pen 4● pan 5● para   1★ paleo 古   2★ para ,辅助,在旁边   3★ pan 广泛的   4★ per 假,坏,自始自 ...

  3. 神奇的口袋(dp)

    有一个神奇的口袋,总的容积是40,用这个口袋可以变出一 些物品,这些物品的总体积必须是40. John现在有n(1≤n ≤ 20)个想要得到的物品,每个物品 的体积分别是a1,a2……an.John可 ...

  4. 003-RHEL7-Linux系统维护管理命令使用

    系统维护管理命令: date  查看日期,设置日期 只有超级用户才能用date命令设置时间 date  --help  显示时间的帮助命令 date{选项} 显示时间格式(以+开头,后面接时间格式) ...

  5. chrome console 阻止 Navigated to

    阻止如图 chrome 如图信息

  6. 如何快速成为一名Linux运维工程师

    如今的互联网,绝大多数的网站.服务.游戏均是跑在Linux上面的,虽说Linux发行版众多,只要玩熟了一种发行版,了解了Linux精髓.基本架构.设计原理,其他都是触类旁通的,千万不要在选择哪一发行版 ...

  7. WPF 之 TreeView节点重命名

    下面的TreeView节点是通过数据双向绑定的方式,绑定到TextBlock控件和TextBox控件的Text属性上,并且让两者绑定相同的属性,同时使TextBox控件刚好完全覆盖TextBlock控 ...

  8. bzoj5016

    题解: 吧询问变成前缀形式 然后莫队 代码: #include<bits/stdc++.h> ; using namespace std; ]; ,L=,R=; ,Ans[N]; bool ...

  9. JavaScrip(三)JavaScrip变量高级操作(字符串,数组,日期)

    一:字符串 charAt() 返回指定位置的字符 indexof() 返回指定字符串首次出现的位置 replace() 替换指定的字符 concat() 连接两个或多个字符串 substr(start ...

  10. eclipse package视图和navigator视图的区别

    package视图是适合开发的视图,因为开发时我们只关注源文件,并不关注编译后的二进制文,所有在该视图中存放二进制文件的classes文件被隐藏了,而navigator视图,就是项目在工作空间中存放的 ...