/**
题目:Death to Binary?
链接:https://vjudge.net/contest/154246#problem/T
题意:略。
思路:
注意事项:
给的字符串存在前导0;
存在0+0 */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+;
const double eps = 1e-;
ll f[];
int la, lb, lc;
void init()
{
f[] = ;
f[] = ;
for(int i = ; i < ; i++){
f[i] = f[i-]+f[i-];
}
} void removeLeadZero(char a[])
{
int len = strlen(a);
int i = ;
while(i<len&&a[i]==''){
i++;
}
if(i==len){
a[] = '';
a[] = '\0';
}else
strcpy(a,a+i);
}
void canonical(char a[])
{
int len = strlen(a);
int flag = ;
char temp[];
int t = ;
temp[t++] = a[];
for(int i = ; i < len; i++){
if(a[i]==a[i-]&&a[i]==''){
flag = ;
if(t!=){
temp[t-] = '';
t--;
}
temp[t++] = '';
temp[t++] = '';
i++;
while(i<len){
temp[t++] = a[i++];
}
break;
}else
{
temp[t++] = a[i];
}
}
temp[t] = '\0';
if(flag) canonical(temp);
strcpy(a,temp);
}
void getC(ll x,char c[])
{
lc = ;
int pos;
for(int i = ; i < ; i++){
if(f[i]>x){
pos = i;
break;
}
}
pos = pos-;
while(pos>=){
if(f[pos]<=x){
c[lc++] = '';
x -= f[pos];
}else
{
c[lc++] = '';
}
pos--;
}
if(lc==){
c[lc++] = '';
}
c[lc] = '\0';
}
void print(char a[],char b[],char c[])
{
canonical(a);
canonical(b);
canonical(c);
//printf("a = %s b = %s c = %s\n",a,b,c);
lc = strlen(c);
la = strlen(a);
lb = strlen(b);
int sp = +lc-la;
while(sp--){
printf(" ");
}
printf("%s\n",a);
printf("+");
sp = +lc-lb-;
while(sp--){
printf(" ");
}
printf("%s\n",b);
printf(" ");
sp = lc;
while(sp--){
printf("-");
}
printf("\n");
printf(" ");
printf("%s\n\n",c);
}
int main()
{
char a[], b[], c[];
init();
while(scanf("%s%s",a,b)==)
{
removeLeadZero(a);
removeLeadZero(b);
//printf("a = %s\n",a);
//printf("b = %s\n",b);
ll sa, sb, sc;
sa = sb = ;
la = strlen(a);
lb = strlen(b);
for(int i = la-; i >= ; i--){
if(a[i]==''){
sa += f[la--i];
}
}
for(int i = lb-; i >= ; i--){
if(b[i]==''){
sb += f[lb--i];
}
} sc = sa+sb;
getC(sc,c);
//printf("a = %s\n",a);
//printf("c = %s\n",c);
//printf("sa = %lld sb = %lld\n",sa,sb);
print(a,b,c);
}
return ;
}

Death to Binary? 分析模拟的更多相关文章

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

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

  2. poj 2116 Death to Binary? 模拟

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

  3. 【教程】手把手教你如何利用工具(IE9的F12)去分析模拟登陆网站(百度首页)的内部逻辑过程

    [前提] 想要实现使用某种语言,比如Python,C#等,去实现模拟登陆网站的话,首先要做的事情就是使用某种工具,去分析本身使用浏览器去登陆网页的时候,其内部的执行过程,内部逻辑. 此登陆的逻辑过程, ...

  4. 2017 Wuhan University Programming Contest (Online Round) C. Divide by Six 分析+模拟

    /** 题目:C. Divide by Six 链接:https://oj.ejq.me/problem/24 题意:给定一个数,这个数位数达到1e5,可能存在前导0.问为了使这个数是6的倍数,且没有 ...

  5. POJ2116 Death to Binary?

    /* POJ2116 Death to Binary? http://poj.org/problem?id=2116 齐肯多夫定理 */ #include <cstdio> #includ ...

  6. SBX(Simulated binary crossover)模拟二进制交叉算子和DE(differential evolution)差分进化算子

    一起来学演化计算-SBX(Simulated binary crossover)模拟二进制交叉算子和DE(differential evolution)差分进化算子 觉得有用的话,欢迎一起讨论相互学习 ...

  7. 从session实现机制分析模拟请求验证码的可行性(转)

    悲剧了,发现写完这篇blog没有配上这个格调超高的标题.   1.0问题背景 现在要实现一个带验证码网站的的自动登陆功能.验证码识别过程不再这篇文章的讨论之中.(之后有篇文章我会详细的总结验证码的识别 ...

  8. Codeforces 916B Jamie and Binary Sequence ( 模拟 && 思维 )

    题意 : 给出一个数 n ,要求你用 k 个二的幂来组成这个数,要求输出这 k 个二的幂的指数,如果有多解情况则优先输出最大指数最小的那一个且要求按字典序输出,不存在则输出 No 分析 :  先来说一 ...

  9. fzu 2250 不可能弹幕结界 分析+模拟,考察思维严谨。

    Problem 2250 不可能弹幕结界 Accept: 5    Submit: 13Time Limit: 1000 mSec    Memory Limit : 65536 KB Problem ...

随机推荐

  1. POP3、IMAP、SMTP邮件协议的理解

    一个热爱技术的菜鸟...用点滴的积累铸就明日的达人 CSDN博客链接: http://blog.csdn.net/my_confesser    正文   今天入职配置OutLook的时候,看到公司的 ...

  2. 使用virtualenv为应用提供了隔离的Python运行环境

    在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时开发多个应用程序,那这 ...

  3. 网络采集软件核心技术剖析系列(4)---使用C#语言如何将html网页转换成pdf(html2pdf)

    一 本系列随笔概览及产生的背景 本系列开篇受到大家的热烈欢迎,这对博主是莫大的鼓励,此为本系列第四篇,希望大家继续支持,为我继续写作提供动力. 自己开发的豆约翰博客备份专家软件工具问世3年多以来,深受 ...

  4. zk删除node模式

    检查状态 状态描述指定的znode的元数据.它包含时间戳,版本号,ACL,数据长度和子znode等细项. 语法 stat /path 示例 stat /FirstZnode 输出 [zk: local ...

  5. 计算两个经纬度之间的距离(python算法)

    EARTH_REDIUS = 6378.137 def rad(d): return d * pi / 180.0 def getDistance(lat1, lng1, lat2, lng2): r ...

  6. javascript快速入门20--Cookie

    Cookie 基础知识 我们已经知道,在 document 对象中有一个 cookie 属性.但是 Cookie 又是什么?“某些 Web 站点在您的硬盘上用很小的文本文件存储了一些信息,这些文件就称 ...

  7. 处理 WebService 中的 Map 对象

    最近,我们讨论了关于 WebService 的相关问题.目前在 Smart 中,可发布两种类型的 WebService,它们是:SOAP 服务 与 REST 服务,您可以根据需要自由选择. 今天,我要 ...

  8. Netty源码分析之NioEventLoop(转)

    原文:http://www.jianshu.com/p/9acf36f7e025 上一章节中,我们分析了Netty服务的启动过程,本章节分析Netty的NioEventLoop是如工作的. NioEv ...

  9. 在基于or1200处理器的SoC上移植linux

    经历了前端的艰苦奋斗.SoC前端设计已经调试完毕,如今直接进入uboot移植   首先cd入u-boot-master 找到子文件夹include下得de2_115.h文件进行改动: (下一步计划:加 ...

  10. 配置git账号和密码

    最开始启动的时候 配置用户名和用户邮箱,安装完git第一件要做的事情! git config --global uesr.name "Sunnshino" git config - ...