/*
POJ2116 Death to Binary?
http://poj.org/problem?id=2116
齐肯多夫定理 */
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <set>
//#define test
using namespace std;
const int Nmax=1e6+;
char s[],a[],b[],c[],tmp[],t[];
long long f[];
vector<long long> v;
vector<long long>::iterator it;
long long scan()
{
char c=getchar();
while(c==' '||c=='\n')
c=getchar();
if(c==-)
return -;
int sz=;
while(c>='' && c<='')
{
s[++sz]=c;
c=getchar();
}
long long x=0LL;
for(int i=;i<=sz;i++)
{
x+=1LL*(s[i]-'')*f[sz-i];
}
return x;
}
int id(long long x)
{
int now=upper_bound(v.begin(),v.end(),x)-v.begin();
if(now!=)
now--;
return now;
}
char* get(long long x)
{
int sz=;
for(int i=;i<=;i++)
tmp[i]='';
//printf("\n");
while(x>)
{
//printf("x:%lld\n",x);
tmp[id(x)]='';
sz=max(sz,id(x));
//printf("%d ",id(x));
//printf("%lld",f[id(x)]);
x-=f[id(x)];
}
//printf("\n");
//for(int i=0;i<=40;i++)
//printf("%c",tmp[i]);
//printf("\n"); //printf("%s\n",tmp); for(int i=sz;i>=;i--)
t[sz-i]=tmp[i];
t[sz+]='\0';
return t;
}
void print()
{
int n=strlen(c);
int sum=n+;
int an=strlen(a);
int bn=strlen(b);
for(int i=;i<=sum-an;i++)
putchar(' ');
printf("%s\n",a);
putchar('+');
for(int i=;i<=sum-bn-;i++)
putchar(' ');
printf("%s\n",b);
putchar(' ');
putchar(' ');
for(int i=;i<=n;i++)
putchar('-');
putchar('\n');
putchar(' ');
putchar(' ');
printf("%s\n\n",c);
}
int main()
{
#ifdef test
#endif
//freopen("poj2166.in","r",stdin);
f[]=1LL;
f[]=2LL;
for(int i=;i<;i++)
f[i]=f[i-]+f[i-];
for(int i=;i<=;i++)
v.push_back(f[i]);
while()
{
long long x=scan();
//printf("%lld\n",x);
if(x==-)
break;
long long y=scan();
if(y==-)
break;
long long ans=x+y;
//long long ttt=40LL;
//while(ttt>0)
//{
//printf("%d\n",id(ttt));
//printf("%lld\n",f[id(ttt)]);
//ttt-=f[id(ttt)];
//}
//strcpy(a,get(40LL));
//printf("%s\n",a);
strcpy(a,get(x));
strcpy(b,get(y));
strcpy(c,get(ans));
print();
}
return ;
}

POJ2116 Death to Binary?的更多相关文章

  1. Death to Binary? 分析模拟

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

  2. poj 2116 Death to Binary? 模拟

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

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

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

  4. [kuangbin带你飞]专题十四 数论基础

            ID Origin Title   111 / 423 Problem A LightOJ 1370 Bi-shoe and Phi-shoe   21 / 74 Problem B ...

  5. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  6. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  7. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  8. kuangbin专题 数论基础 part1?

    线段树专题太难了,那我来做数学吧! 但数学太难了,我......(扯 这两天想了做了查了整理了几道数学. 除了一些进阶的知识,像莫比乌斯反演,杜教筛,min25学不会我跳了,一些基础的思维还是可以记录 ...

  9. ACM--[kuangbin带你飞]--专题1-23

    专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...

随机推荐

  1. uboot向内核模块传递参数的方法

    1 模块参数 定义模块参数 1 module_param(name, type, perm); 定义一个模块参数, name 变量名 type 数据类型 bool:布尔型 invbool:一个布尔型( ...

  2. 君正Ingenic X1000E_halley2 更改Logo

    有两种方法可以改变开机logo,编译进内核或者修改u-boot. <一>.编译进内核 一. 制作LOGO图片(可以使用gimp) 1. 制作一个.ppm格式图片(logo_tvu_clut ...

  3. android SearchView 样式修改

    try { Class<?> argClass=mSearchView.getClass(); //指定某个私有属性 Field mSearchHintIconField = argCla ...

  4. ConcurrentDictionary中的 TryRemove

    class A { internal int value; } ConcurrentDictionary<int, A> dic = new ConcurrentDictionary< ...

  5. TensorFlow Lite demo——就是为嵌入式设备而存在的,底层调用NDK神经网络API,注意其使用的tf model需要转换下,同时提供java和C++ API,无法使用tflite的见后

    Introduction to TensorFlow Lite TensorFlow Lite is TensorFlow’s lightweight solution for mobile and ...

  6. Codeforces--629B--Far Relative’s Problem(模拟)

    Far Relative's Problem Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I ...

  7. codevs1288 埃及分数(IDA*)

    1288 埃及分数  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description 在古埃及,人们使用单位分数的和(形如1/a的 ...

  8. JDK多任务执行框架(Executor框架)

    Executor的常用方法 为了更好的控制多线程,JDK提供了一套线程框架Executor,帮助开发人员有效地进行线程控制.它们都在java.util.concurrent包中,是JDK开发包的核心. ...

  9. Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have A

    Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you ...

  10. A - Supermarket

    Problem description We often go to supermarkets to buy some fruits or vegetables, and on the tag the ...