Death to Binary?
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1707   Accepted: 529

Description

The group of Absurd Calculation Maniacs has discovered a great new way how to count. Instead of using the ordinary decadic numbers, they use Fibonacci base numbers. Numbers in this base are expressed as sequences of zeros and ones similarly to the binary numbers, but the weights of bits (fits?) in the representation are not powers of two, but the elements of the Fibonacci progression (1, 2, 3, 5, 8,... - the progression is defined by F0 = 1, F1 = 2 and the recursive relation Fn = Fn-1 + Fn-2 for n >= 2).

For example 1101001Fib = F0 + F3 + F5 + F6 = 1 + 5 + 13 + 21 = 40.

You may observe that every integer can be expressed in this base,
but not necessarily in a unique way - for example 40 can be also
expressed as 10001001Fib. However, for any integer there is a
unique representation that does not contain two adjacent digits 1 - we
call this representation canonical. For example 10001001Fib is a canonical Fibonacci representation of 40.

To prove that this representation of numbers is superior to the
others, ACM have decided to create a computer that will compute in
Fibonacci base. Your task is to create a program that takes two numbers
in Fibonacci base (not necessarily in the canonical representation) and
adds them together.

Input

The
input consists of several instances, each of them consisting of a single
line. Each line of the input contains two numbers X and Y in Fibonacci
base separated by a single space. Each of the numbers has at most 40
digits. The end of input is not marked in any special way.

Output

The output for each instance should be formated as follows:

The first line contains the number X in the canonical
representation, possibly padded from left by spaces. The second line
starts with a plus sign followed by the number Y in the canonical
representation, possibly padded from left by spaces. The third line
starts by two spaces followed by a string of minus signs of the same
length as the result of the addition. The fourth line starts by two
spaces immediately followed by the canonical representation of X + Y.
Both X and Y are padded from left by spaces so that the least
significant digits of X, Y and X + Y are in the same column of the
output. The output for each instance is followed by an empty line.

Sample Input

11101 1101
1 1

Sample Output

   100101
+ 10001
-------
1001000 1
+ 1
--
10

Source

题意:给你一个两个字符串,一个字符串的值等于为1位置的斐波那契的和,比如1101001Fib = F0 + F3 + F5 + F6 = 1 + 5 + 13 + 21 = 40,一个值可能有多种不同的写法,需要改成没有相邻的1的写法, 写成加法的式子;
思路:模拟,坑点  0 0;和前导0;
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define ll long long
#define esp 1e-13
const int N=1e4+,M=1e6+,inf=1e9+,mod=;
string s1,s2,s3;
ll a[N];
void init()
{
a[]=;
a[]=;
for(int i=;i<=;i++)
a[i]=a[i-]+a[i-];
}
ll getnum(string aa)
{
int x=aa.size();
ll sum=;
for(int i=;i<x;i++)
if(aa[i]=='')
sum+=a[i];
return sum;
}
void check(ll x,string &str)
{
int i;
for(i=;i>=;i--)
if(x>=a[i])
break;
for(int t=i;t>=;t--)
if(x>=a[t])
{
str+='';
x-=a[t];
}
else
str+='';
if(i<)
str+='';
}
int main()
{
int x,y,i,z,t;
init();
while(cin>>s1>>s2)
{ reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
ll num1=getnum(s1);
ll num2=getnum(s2);
ll num3=num1+num2;
s1.clear();
s2.clear();
s3.clear();
check(num1,s1);
check(num2,s2);
check(num3,s3);
printf(" ");for(i=;i<s3.size()-s1.size();i++)printf(" ");cout<<s1<<endl;
printf("+ ");for(i=;i<s3.size()-s2.size();i++)printf(" ");cout<<s2<<endl;
printf(" ");for(i=;i<s3.size();i++)printf("-");cout<<endl;
printf(" ");cout<<s3<<endl;
cout<<endl;
}
return ;
}

poj 2116 Death to Binary? 模拟的更多相关文章

  1. Death to Binary? 分析模拟

    /** 题目:Death to Binary? 链接:https://vjudge.net/contest/154246#problem/T 题意:略. 思路: 注意事项: 给的字符串存在前导0: 存 ...

  2. POJ2116 Death to Binary?

    /* POJ2116 Death to Binary? http://poj.org/problem?id=2116 齐肯多夫定理 */ #include <cstdio> #includ ...

  3. Death to Binary? (模拟)题解

    思路: 除去前导0,注意两个1不能相邻(11->100),注意 0 *** 或者*** 0或者0 0情况 用string的reverse()很舒服 代码: #include<cstdio& ...

  4. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  5. POJ 1027 The Same Game(模拟)

    题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...

  6. POJ 3414 Pots【bfs模拟倒水问题】

    链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...

  7. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  8. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  9. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

随机推荐

  1. Java工程师面试题整理[社招篇]

    http://blog.csdn.net/jackfrued/article/details/44921941 1.面向对象的特征有哪些方面?2.访问修饰符public,private,protect ...

  2. 一篇搞定SQLAlchemy--关系对象映射

    要使用SQLAlchemy,必须先下载这个模块 pip3 install sqlalchemy 或 pycharm File--> Settings-->project...-->P ...

  3. 如何搭建一个 Git 版本控制服务端?

    Gogs 下载和安装 https://github.com/gogits/gogs # 下载二进制压缩包 不检查服务器证书 root@cheungxiongwei:~# wget --no-check ...

  4. CF85D Sum of Medians

    CF85D Sum of Medians 题意翻译 一个集合,初始为空.现有三个操作: 1.add:向集合里加入数x,保证加入前集合中没有数x: 2.del:从集合中删除数x,保证删除前集合中有x: ...

  5. 编译java-cef

    javacef即java Chromium Embedded Framework,其功能是通过在java应用中嵌入谷歌浏览器内核Chromium. 编译java-cef的过程可参考以下文档及视频: h ...

  6. 协程 Gevent

    # 协程应用:爬虫 from gevent import monkey;monkey.patch_all() import gevent import requests import time def ...

  7. 转:9个offer,12家公司,35场面试 从微软到谷歌,应届计算机毕业生的2012求职之路 !!!

    1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...

  8. Java进阶学习:将文件上传到七牛云中

    Java进阶学习:将文件上传到七牛云中 通过本文,我们将讲述如何利用七牛云官方SDK,将我们的本地文件传输到其存储空间中去. JavaSDK:https://developer.qiniu.com/k ...

  9. 预防SQL注入攻击

    /** * 预防SQL注入攻击 * @param string $value * @return string */ function check_input($value) { // 去除斜杠 if ...

  10. javascript; JS版HtmlEncode方法,结果与C#中HttpUtility.HtmlEncode方法一样。

    <script type="text/javascript"> function HTMLEncode(html) { var temp = document.crea ...