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. 【BZOJ2213】[Poi2011]Difference DP

    [BZOJ2213][Poi2011]Difference Description A word consisting of lower-case letters of the English alp ...

  2. 《从零开始学Swift》学习笔记(Day 9)——离开表达式你试试!

    原创文章,欢迎转载.转载请注明:关东升的博客 表达式啊是很重要地. 在Swift中,表达式有3种形式. 不指定数据类型 var a1 = 10 指定数据类型 var a1:Int  = 10 使用分号 ...

  3. 1366 贫富差距(floyed)

    1366 贫富差距 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个国家有N个公民,标记为0,1,2,...,N-1,每个公民有一 ...

  4. Strange Optimization(扩展欧几里得)

    Strange Optimization Accepted : 67   Submit : 289 Time Limit : 1000 MS   Memory Limit : 65536 KB Str ...

  5. 如何自己实现一套EasyNVR这样的无插件流媒体服务器

    EasyNVR流媒体解决方案 EasyNVR能够通过简单的网络摄像机通道配置,将传统监控行业里面的高清网络摄像机IP Camera.NVR等具有RTSP协议输出的设备接入到EasyNVR,EasyNV ...

  6. EasyNVR和EasyDSS云平台联手都不能解决的事情,只有国标GB28181能解决了

    需求痛点 我们经常收到这样一种需求,就是将客户手里的各种类型的网络摄像机IPC和网络硬盘录像机NVR进行统一的整合接入和管理,并进行常规的直播.存储.录像检索和回放等操作,而这个时候我们通常会选择用E ...

  7. jquery遍历json与数组方法总结

    来自:http://www.php100.com/html/program/jquery/2013/0905/5927.html 先我们来参考each() 方法,each()规定为每个匹配元素规定运行 ...

  8. Axis 调用.net WebServic接口出现:验证消息的安全性时错误发生

    解决方法:call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS); 參考:http://www.blogjav ...

  9. ThreadLocal (三):为何TransmittableThreadLocal

    一.示例 线程池内的线程并没有父子关系,所以不适合InheritableThreadLocal的使用场景 public class ThreadPoolInheritableThreadLocalDe ...

  10. 【转载】Java中使用Jedis操作Redis

    1 package com.test; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import java.util.Li ...