POJ2116 Death to Binary?
/*
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?的更多相关文章
- Death to Binary? 分析模拟
/** 题目:Death to Binary? 链接:https://vjudge.net/contest/154246#problem/T 题意:略. 思路: 注意事项: 给的字符串存在前导0: 存 ...
- poj 2116 Death to Binary? 模拟
Death to Binary? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1707 Accepted: 529 D ...
- Death to Binary? (模拟)题解
思路: 除去前导0,注意两个1不能相邻(11->100),注意 0 *** 或者*** 0或者0 0情况 用string的reverse()很舒服 代码: #include<cstdio& ...
- [kuangbin带你飞]专题十四 数论基础
ID Origin Title 111 / 423 Problem A LightOJ 1370 Bi-shoe and Phi-shoe 21 / 74 Problem B ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- kuangbin专题 数论基础 part1?
线段树专题太难了,那我来做数学吧! 但数学太难了,我......(扯 这两天想了做了查了整理了几道数学. 除了一些进阶的知识,像莫比乌斯反演,杜教筛,min25学不会我跳了,一些基础的思维还是可以记录 ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
随机推荐
- #定位系统性能瓶颈# sysdig
安装方法: curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash [root@l ...
- 学习笔记二十三——字符函数库cctype【转】
本文转载自: 字符函数库cctype 在头文件cctype(ctype.h)中定义了一些函数原型,可以简化输入确定字符是否为大写字母.数字.标点符号等工作. 例如: 如果ch是一个字母,则isalph ...
- Android系统Recovery工作原理之使用update.zip升级过程分析(七)---Recovery服务的核心install_package函数【转】
本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465514 一. Recovery服务的核心install_package(升级 ...
- Base Class Doesn't Contain Parameterless Constructor?
http://stackoverflow.com/questions/7689742/base-class-doesnt-contain-parameterless-constructor #regi ...
- python pickle to json
ref: https://gist.github.com/Samurais/567ebca0f59c612eb977065008aad867 ''' Convert a pkl file into j ...
- RCF:一个相当不错的C++分布式RPC框架
RCF(远程调用框架)是一个可以移植的C++进程间通信框架,使用C++语言特性,提供了一个简单高效的编写分布式C++软件的途径.RCF利用编译时多态清晰分开了接口和实现. 和传统的RPC框架如CORB ...
- Oracle Instant Client 安装配置
一.下载 下载地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html 这是Ora ...
- PCB MS SQL 小写转大写
由于SQL Server允许为小写进入 ,导致数据库中存在小写,在数据集成到MES或ERP时报错,Oracle要求大写导致, 需转换为大写,可通过以下语句,查询所有小写数据,再更新.
- [Apple开发者帐户帮助]三、创建证书(5)创建WatchKit服务证书
WatchKit服务证书允许您使用Apple推送通知(APN)将更新推送到Apple Watch上的复杂功能. 所需角色:帐户持有人或管理员. 在证书,标识符和配置文件中,从左侧的弹出菜单中选择iOS ...
- TPshop规格组合错误
TPshop规格组合错误 修改: admin/logic/goodslogic.class.php 中 方法:getSpecInput() 中 asort($spec_arr_sort) 去掉