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 ...
随机推荐
- arm linux串口蓝牙工具移植及使用【转】
本文转载自:http://blog.csdn.net/hclydao/article/details/51451725 p6212中串口蓝牙在linux下的使用记录 一.linux蓝牙工具移植 主要使 ...
- wox 快速搜索程序
windows启动栏的搜索,会经常找不到exe. 使用wox可以非常快速的找到启动程序 https://github.com/Wox-launcher/Wox/ 安装完成后,默认alt+space出现 ...
- C#可定制的数据库备份和恢复程序 (讲解流程)
可定制的数据库备份和恢复程序 tashanzhishi [原作] 关键字 数据库 备份 恢复 出处 在我们做数据库系统的程序时,经常需要为客户做一个数据库的备份和恢复程序,特别是对于一些非专业的数据库 ...
- 认证与授权协议对比:OAuth2、OpenID、SMAL
认证授权是目前大多数系统都必须要实现都功能,认证就是验证用户都身份,授权就是验证身份后对受限资源的访问控制.最开始是单个平台要做,后来在互联网时代到来,一个账户可登陆多个平台,然后是各种开放平台账户共 ...
- EOJ 3194 字符串消除
给定一个由大写字母’A’.’B’.’C’构成的字符串s,按如下进行消除过程: 1.字符串s中连续相同字母组成的子串,如果子串的长度大于1,那么这些子串会被同时消除,余下的字符拼成新的字符串. 例如:” ...
- 跟渣渣辉玩ffms
[SQL] /* Navicat MySQL Data Transfer Source Server : root Source Server Version : 50717 Source Host ...
- Play on Words(欧拉路)
http://poj.org/problem?id=1386 题意:给定若干个单词,若前一个的尾字母和后一个单词的首字母相同,则这两个单词可以连接,问是否所有的单词都能连接起来. 思路:欧拉路的判断, ...
- css3 选择器 权重问题 (第二部分)
这篇博文有关css的权重问题,我个人认为这是css知识中很重要的一个知识点.因为在开发的过程能中我们会经常遇到这种问题,特别是如果你使用框架的时候,有些框架的某些标签有一些默认的样式.所以我们可以通过 ...
- golang 获取statuscode
最近日志打印的时候需要打印状态码,但是因为interface的原因直接获取失败,http.Request里面的response不知道怎么使用,所以就自己重写writeheader,write来截取st ...
- 文字水平居中和垂直居中的CSS
首先选择一个需要显示文字的选择器,我这里选择的是微信小程序里面的<view>选择器,在其他语言(如html)的选择器里是一样的做法: <view class="btn-it ...