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
0
and1
. - 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的原因,但发现自己对计算机的数字表示和运算十分陌生,于是只好恶补一下.以下是恶补后的成果: 基础野:细说 ...
随机推荐
- jedata日期控件的开始结束日期设置
<span class="wstxt">开始日期:</span><input type="text" class="wo ...
- Win10系列:C#应用控件基础2
HyperlinkButton控件 HyperlinkButton控件是以超链接文本形式显示的按钮,可以为其NavigateUri属性设置一个URI地址,当单击超链接文本按钮时,将会使用浏览器打开在H ...
- laravel 连表查询数据库
$this->model ->select($field) ->leftJoin('b', 'b.cid', '=', 'a.id') ->orderBy("a.ad ...
- linux command useradd
Linux command useradd [Purpose] Learning linux command useradd to create a new user or update ...
- js的event.preventDefault()与event.stopPropagation()
event.preventDefault()用法介绍 该方法将通知 Web 浏览器不要执行与事件关联的默认动作(如果存在这样的动作).例如,如果 type 属性是 "submit" ...
- ASPNET MVC5 根 core
Asp.Net Core MVC的开源地址:https://github.com/aspnet/Mvc Asp.net MVC的开源地址:http://aspnetwebstack.codeplex. ...
- DevExpress WinForms v18.2新版亮点(八)
买 DevExpress Universal Subscription 免费赠 万元汉化资源包1套! 限量15套!先到先得,送完即止!立即抢购>> 行业领先的.NET界面控件2018年第 ...
- freemarker学习 (servlet + freemarker -> Struts2+freemarker -> springMVC+freemarker)
什么是freemarker? freemarker类似于jsp,但不是jsp!怎么说呢?freemarker文件后缀是.ftl,它不像jsp本质是servlet,它将构建模板.解析模板.使用模板分离开 ...
- L304 What Is Death?
How should we define the death of a person? Philosophers and physicians have long pondered this ques ...
- vue 编译原理 简介
来源 tinycompile 关于vue的内部原理其实有很多个重要的部分,变化侦测,模板编译,virtualDOM,整体运行流程等. 之前写过一篇<深入浅出 - vue变化侦测原理> 讲了 ...