Atcode ABC105-C:Base -2 Number
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
0and1. - Unless S=S=
0, the initial character of SS is1. - 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的更多相关文章
- C# 中的关键字之:base、this 【转】
C# 中的关键字之:base.this. ba ...
- 动手写个数字输入框1:input[type=number]的遗憾
前言 最近在用Polymer封装纯数字的输入框,开发过程中发现不少坑,也有很多值得研究的地方.本系列打算分4篇来叙述这段可歌可泣的踩坑经历: <动手写个数字输入框1:input[type=nu ...
- 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时出现如下报错 ...
- 配置iOS项目的设备系统目标设置:Base SDK和Deployment Target
配置iOS项目的设备系统目标设置:Base SDK和Deployment Target Xcode为开发者提供了两个可配置的设置:第一个是Base SDK,第二个是iOS的Deployment Tar ...
- 第193天:js---Math+Error+Number+Object总结
一.Math 随机选取 //随机选取 function getRandom (begin,end){ return Math.floor(Math.random()*(end-begin))+begi ...
- 【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 ...
- oracle创建jobs定时任务报错:PLS-00306: wrong number or types of arguments in call to 'JOB'
原脚本: begin sys.dbms_job.submit(job => job, what => 'xxx;', ...
- EF:oracle的number类型映射为C#的boolean类型
一开始用下面的方法映射, Property(p => p.IsFixed).HasColumnName("IS_FIXED").HasColumnType("num ...
- JS魔法堂:再识Number type
Brief 本来只打算理解JS中0.1 + 0.2 == 0.30000000000000004的原因,但发现自己对计算机的数字表示和运算十分陌生,于是只好恶补一下.以下是恶补后的成果: 基础野:细说 ...
随机推荐
- thinkphp 3.2 加载第三方库 第三方命名空间库
tp 自动加载的介绍: http://document.thinkphp.cn/manual_3_2.html#autoload 第三方库不规范库 不适用命名空间的库 可以使用import函数导入,其 ...
- chrome hosts
# Go Hosts# 2017-05-02 02:13:04# Localhost (DO NOT REMOVE)127.0.0.1 localhost::1 localhost ip6 ...
- PhpStudy的安装及使用教程
1.PhpStudy是什么 phpstudy是一个PHP调试环境的程序集成包,phpStudy软件集成了最新的Apache.PHP.MySQL.phpMyAdmin.ZendOptimizer,一次性 ...
- How to calculate bits per character of a string? (bpc) to read
http://stackoverflow.com/questions/17797922/how-to-calculate-bits-per-character-of-a-string-bpc up ...
- Linux第六周作业
一 实验过程 1 先进入LinuxKernel环境下,更新menu代码到最新版,用到的命令为rm menu -rf //强制删除当前menu,git clone http://git.shiyanlo ...
- ubuntu中更新.netcore到2.1版本
如果需要安装新版本到dotnetcore,需要先卸载旧版本(https://github.com/dotnet/core/blob/master/release-notes/download-arch ...
- MyEclipse常用设置和快捷键
Java快捷键 1.注释快捷键 先敲/ 再敲两个** Enter 回车 2.system.out.println(); 常用设置 [子类继承父类] [编码字体设置] 删除当前行:ctrl+d ...
- Python格式化字符 %s %d %f
格式 描述%% 百分号标记 #就是输出一个%%c 字符及其ASCII码%s 字符串%d 有符号整数(十进制)%u 无符号整数(十进制)%o 无符号整数(八进制)%x 无符号整数(十六进制)%X 无符号 ...
- 修改Host,配置域名访问
修改Host,配置域名访问 虽然我们已经能够通过localhost访问本地网站了,为了提高逼格,我们可以修改host文件,设置一个自己喜欢的域名指向本地网站,岂不是更高大上. 明确需求 通过配置, ...
- gulp安装和使用
1.全局安装gulp:sudo npm install -g gulp 2.代码根目录:npm install 3.gulp 开始编译(在项目根目录下创建一个名为 gulpfile.js 的文件) 注 ...