/**
题目: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. RxJava 2.x 理解-2

    操作符总结: http://reactivex.io/documentation/operators.html https://github.com/ReactiveX/RxJava/wiki Ope ...

  2. telnet协议的作用详解,以及telnet端口号介绍

    转:http://www.ctowhy.com/382.html Telnet协议,工作在TCP/IP协议栈的“应用层”,telnet是一种使用命令行的远程终端管理的协议,可以远程连接到网络设备上,并 ...

  3. nfs mount 故障 mount.nfs: access denied by server while mounting 10.0.100.208:/backup_usb

    生产环境: 服务端centos7.2,客户端:ubuntu16.04 挂载出现的故障: root@HDCtrl100:/mnt# mount -t nfs 10.0.100.208:/backup_u ...

  4. Linux源码编译安装MySQL5.7

    目录[-] 一.环境准备: 二.升级系统: 三.做一些准备工作(以下Linux命令均在su到root用户操作): 四.开始编译安装mysql-5.7.9: 一.环境准备: 我尝试过以下环境都是能成功的 ...

  5. 转:解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误

    Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN ...

  6. 深入浅出 消息队列 ActiveMQ (转)

    启动成功就可以访问管理员界面:http://localhost:8161/admin,默认用户名和密码admin/admin.如果你想修改用户名和密码的话,在conf/jetty-realm.prop ...

  7. puppeteer 相关知识

    page.waitForNavigation: 但我们通过代码执行到页面跳转时,我们需要等待跳转完成再作其他事情.使用page.waitForNavigation会等待跳转完成.(一般作用在点击链接或 ...

  8. vue 表单验证实例

    1.注册 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  9. mui 根据 json 数据动态创建列表

    使用 underscore.js 模块解析 Underscore提供了一个轻量级的模板解析函数,它可以帮助我们有效地组织页面结构和逻辑. 实例: <!DOCTYPE html> <h ...

  10. iOS学习笔记23-音效与音乐

    一.音频 在iOS中,音频播放从形式上能够分为音效播放和音乐播放. * 音效: * 主要指一些短音频的播放,这类音频一般不须要进行进度.循环等控制. * 在iOS中.音效我们是使用AudioToolb ...