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的原因,但发现自己对计算机的数字表示和运算十分陌生,于是只好恶补一下.以下是恶补后的成果: 基础野:细说 ...
随机推荐
- C#执行Sql 时,出现“算术运算导致溢出”问题,如何解决?
昨天在C#执行oracle的sql语句时,总是报错,原先在pl/sql 执行sql语句是可以的,在C#执行就报“算术运算导致溢出”问题 SQL语句 select A.SKU_ID 商品标识,A.COL ...
- Mac上搭建nginx教程
1.安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in ...
- Saiku的基本使用介绍(三)
Saiku的基本使用介绍(这里都是使用Admin用户登录系统) 1.启动安装好的Saiku ( ./start-saiku.sh ) ,浏览器使用访问系统 http://localhost:8080 ...
- vue-router-8-路由组件传参
在组件中使用$route会使之与其对应路由形成高度耦合,使用props解耦 const User = { props: ['id'], template: '<div>User{{ id ...
- Linux系统管理常用命令用法总结(1)
1.usermod可用来修改用户帐号的各项设定. usermod [-LU][-c <备注>][-d <登入目录>][-e <有效期限>][-f <缓冲天数& ...
- MFC 中GetClientRect、ClientToScreen、GetWindow、RectScreenToClient的使用
CWnd* pWnd = GetDlgItem(IDB_BUT_RECOGNIZE); pWnd->GetClientRect(&rect); //指该控件自身客户区的矩形,原点为控 ...
- Android开发 ---Button的OnClickListener的三种实现方法
button的OnClickListener的三种实现方法 onclick事件的定义方法,分为三种,分别为 1.在xml中进行指定方法: 2.在Actitivy中new出一个OnClickListen ...
- 基于.NET Core 框架搭建WebApi项目
一 什么是.NET Core? 随着2014年 Xamarin和微软发起.NET基金会,微软在2014年11月份开放.NET框架源代码.在.NET开源基金会的统一规划下诞生了.NET Core .也就 ...
- springMVC学习五(转发和乱码)
摘录http://www.cnblogs.com/xdp-gacl/p/3798347.html http://www.cnblogs.com/xdp-gacl/p/3798347.html 四个很重 ...
- ChinaCock界面控件介绍-CCButton
即将发布的ChinaCock新版本,将带来一个CCButton控件,实现可视按钮.Delphi原生的Button,在上面滑动后,当释放手指时会误触发OnClick事件,这不是我们想要的结果,CCBut ...