/**
题目: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. 关于scanf函数的返回值问题

    如: scanf("%d%d",&a,&b); 1.如果a和b都被成功读入,则scanf的返回值为2 2.如果只有a被成功读入,那么返回值为1 3.如果a和b都未被 ...

  2. 学习实践:使用模式,原则实现一个C++数据库訪问类

    一.概述 在我參与的多个项目中.大家使用libMySQL操作MySQL数据库,并且是源代码级复用,在多个项目中同样或相似的源代码.这种复用方式给开发带来了不便. libMySQL的使用比較麻烦.非常e ...

  3. cpu压力测试

    一.cpu压力测试 1.安装stress软件 sudo apt-get install stress #加压 nohup stress --cpu 8 & #查看cpu负载 top

  4. VR开发者必看:4大最为值得关注的内容平台【转】

            时间 2016-01-19 14:12:57 原文  http://www.sfw.cn/xinwen/478369.html 主题 虚拟现实 Oculus 对很多有意涉及VR行业的内 ...

  5. ubuntu14.04 server 安装docker

    安装docker服务 $ curl -sSL https://get.docker.com/ | sh   $ ocker run hello-world 测试docker是否安装成功 ubuntu ...

  6. [Functional Programming] Draw Items from One JavaScript Array to Another using a Pair ADT

    We want to be able to pick nine random cards from an array of twelve cards, but can run into problem ...

  7. docker集群——介绍Mesos+Zookeeper+Marathon的Docker管理平台

    容器为用户打开了一扇通往新世界的大门,真正进入这个容器的世界后,却发现新的生态系统如此庞大.在生产使用中,不论个人还是企业,都会提出更复杂的需求.这时,我们需要众多跨主机的容器协同工作,需要支持各种类 ...

  8. 倍福TwinCAT(贝福Beckhoff)应用教程11.1 TwinCAT应用小程序1 如何读写数字量模拟量输入输出(DI,DO,AI,AO)

    常见的模拟量模块(还有更高端和更低端的,使用方法都一样) EL3054和EL4024(4路模拟量输入和输出模块)   常见的数字量模块(还有更高端和更低端的,使用方法都一样) EL1809和EL280 ...

  9. Charles的HTTPS抓包方法及原理,下载安装ssl/https证书

    转自:https://zhubangbang.com/charles-https-packet-capture-method-and-principle.html 本文的Charles,适应windo ...

  10. vue手机端横屏竖屏切换

    1.建一个空白的vue文件,添加上如下代码 data() { this.$router.go(-1) return {} }   2.在需要横屏竖屏切换的页面中加入如下代码: beforeMount( ...