/*
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. 为Chrome开发插件提高工作效率

    工作生活,什么最珍贵,我觉得是时间,怎么节约时间是一个最重要的问题,如果你有重复的工作在网页上,请接着看 上手步骤: 打开https://developer.chrome.com/extensions ...

  2. C# winform 组件---- folderBrowserDialog与openFileDialog(转)

    C# winform 组件---- folderBrowserDialog与openFileDialog 2009-06-27 13:36 2153人阅读 评论(1) 收藏 举报 winformc#b ...

  3. B1922 [Sdoi2010]大陆争霸 最短路

    我一直都不会dij的堆优化,今天搞了一下...就是先弄一个优先队列,存每个点的数据,然后这个题就加了一点不一样的东西,每次的最短路算两次,一次是自己的最短路,另一次是机关的最短路,两者取最大值才是该点 ...

  4. This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery

    This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'的意思是,这版本的 MySQL 不支持使 ...

  5. 洛谷P3047 [USACO12FEB]Nearby Cows(树形dp)

    P3047 [USACO12FEB]附近的牛Nearby Cows 题目描述 Farmer John has noticed that his cows often move between near ...

  6. BZOJ 1511 KMP

    题意:求出每个前缀的最长周期之和(等于本身的算0) 思路: 求出来next数组  建出next树 找到不为0的最小的 n减去它就是答案 //By SiriusRen #include <cstd ...

  7. SQLServer2008 将本地excel导入到远程服务器表

    --1.创建链接服务器,相当于创建一个访问远程数据库的快捷方式 exec sp_addlinkedserver 'TestLink', ' ', 'SQLOLEDB ', '111.11.1.111' ...

  8. Windows phone开发 网络编程之HttpWebRequest

    HttpWebRequest和WebClient的区别1,HttpWebRequest是个抽象类,所以无法new的,需要调用HttpWebRequest.Create();2,其Method指定了请求 ...

  9. 查看Oracle数据库表空间大小,是否需要增加表空间的数据文件

    在数据库管理中,磁盘空间不足是DBA都会遇到的问题,问题比较常见. --1查看表空间已经使用的百分比 Sql代码 select a.tablespace_name,a.bytes/1024/1024 ...

  10. UID卡、CUID卡、FUID卡的区别

    UID卡(国外称GEN1) 所有区块可被重复读写 卡片ID可改且使用后门指令更改ID ID可被重复修改 响应后门指令(意味着可被使用后门指令检测是否为克隆卡的机器发现) CUID卡(国外称GEN2) ...