Description

One day Vasya was solving arithmetical problems. He wrote down an expression a + b = c in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries to find excuses. He says that he simply forgot to write down several digits in numbers a, b and c, but he can't remember what numbers they actually were. Help Vasya, find such numbers x, y and z, with which the following conditions are met:

x + y = z,
    from the expression x + y = z several digits can be erased in such a way that the result will be a + b = c,
    the expression x + y = z should have the minimal length.

Input

The first and only input line contains the expression a + b = c (1 ≤ a, b, c ≤ 106, a, b and c don't contain leading zeroes) which is the expression Vasya wrote down.
Output

Print the correct expression x + y = z (x, y and z are non-negative numbers without leading zeroes). The expression a + b = c must be met in x + y = z as a subsequence. The printed solution should have the minimal possible number of characters. If there are several such solutions, you can print any of them.
Examples
Input

2+4=5

Output

21+4=25

Input

1+1=3

Output

1+31=32

Input

1+1=2

Output

1+1=2

正解:搜索

解题报告:

  今天考试T6,9道题里面唯一一道没动的,开始以为是E题就会很难...

  简单思路就是搜索,每次看一下当前的个位是否相等,如果相等,那么显然可以约掉这个已经相等的个位并只处理高位,当然记得进位;否则,我们考虑a、b、c三个元素,保持两个不变,我们把第三个增加一位使得末位与另外两位对应,然后其余部分直接往前推一位,也就是×10。直到c=0,那么肯定只需要把c的最高位补一个a+b剩下的数就可以了,算一下位数。当然要加一个最优性剪枝。

 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
int ans,ansa,ansb;
LL mi[]; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void dfs(LL a,LL b,LL c,LL nowa,LL nowb,LL jin,int nowl,int wei){
if(nowl>=ans) return ;
if(a==&&b==&&c==&&jin==) { ans=nowl; ansa=nowa; ansb=nowb; return ; }
if(c==) {
int tot=; LL lin=a+b+jin; while(lin) tot++,lin/=;//全部加给c
dfs(,,,nowa+a*mi[wei],nowb+b*mi[wei],,nowl+tot,wei);
return;
}
if((a+b+jin)%==c%) dfs(a/,b/,c/,nowa+a%*mi[wei],nowb+b%*mi[wei],(a%+b%+jin)/,nowl,wei+);//去掉已经相等的低位部分,记得给公共的低位部分进位
else{
dfs(a*+(c+-b%-jin)%,b,c,nowa,nowb,jin,nowl+,wei);//a后面加一位与前两个数还有进位的和的个位部分
dfs(a,b*+(c+-a%-jin)%,c,nowa,nowb,jin,nowl+,wei);//b后面加一位与前两个数还有进位的和的个位部分
dfs(a,b,c*+(a+b+jin)%,nowa,nowb,jin,nowl+,wei);///c后面加一位与前两个数还有进位的和的个位部分
}
} inline void work(){
int a,b,c; scanf("%d+%d=%d",&a,&b,&c);
ans=; mi[]=; for(int i=;i<=;i++) mi[i]=mi[i-]*;
dfs(a,b,c,,,,,);
printf("%d+%d=%d",ansa,ansb,ansa+ansb);
} int main()
{
work();
return ;
}

codeforces 58E:Expression的更多相关文章

  1. 【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains no ...

  2. [转]打造自己的LINQ Provider(上):Expression Tree揭秘

    概述 在.NET Framework 3.5中提供了LINQ 支持后,LINQ就以其强大而优雅的编程方式赢得了开发人员的喜爱,而各种LINQ Provider更是满天飞,如LINQ to NHiber ...

  3. ASP.NET MVC:Expression Trees 作为参数简化查询

    ASP.NET MVC 引入了 ModelBinder 技术,让我们可以在 Action 中以强类型参数的形式接收 Request 中的数据,极大的方便了我们的编程,提高了生产力.在查询 Action ...

  4. 解决mysql报错:- Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'

    mysql执行报错: - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated c ...

  5. 打造自己的LINQ Provider(上):Expression Tree揭秘

    概述 在.NET Framework 3.5中提供了LINQ 支持后,LINQ就以其强大而优雅的编程方式赢得了开发人员的喜爱,而各种LINQ Provider更是满天飞,如LINQ to NHiber ...

  6. js进阶正则表达式实现过滤字符串(RegExp对象操作正则表达式)(正则:regular)(表达式:expression)

    js进阶正则表达式实现过滤字符串(RegExp对象操作正则表达式)(正则:regular)(表达式:expression) 一.总结 1.str_replace:正则作用:高效快速匹配 2.break ...

  7. Codeforces 58E Expression (搜索)

    题意:给你一个可能不正确的算式a + b = c, 你可以在a,b,c中随意添加数字.输出一个添加数字最少的新等式x + y  = z; 题目链接 思路:来源于这片博客:https://www.cnb ...

  8. Codeforces 731C:Socks(并查集)

    http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...

  9. Codeforces 747D:Winter Is Coming(贪心)

    http://codeforces.com/problemset/problem/747/D 题意:有n天,k次使用冬天轮胎的机会,无限次使用夏天轮胎的机会,如果t<=0必须使用冬轮,其他随意. ...

随机推荐

  1. ng-bind的使用

    由于JS是单线程的,当HTML页面执行alert的时候,会中断下面代码的运行,所以为了良好的用户体验,当需要在页面使用{{name}}的时候,通常不这样直接输出,而是用ng-bind绑定model数据 ...

  2. PHP 魔术引号

    1.魔术引号的作用是什么? ​ 魔术引号设计的初衷是为了让从数据库或文件中读取数据和从请求中接收参数时,对单引号.双引号.反斜线.NULL加上一个一个反斜线进行转义,这个的作用跟addslashes( ...

  3. Linux中查看各文件夹大小命令du -h --max-depth=1

    http://blog.csdn.net/ouyang_peng/article/details/10414499 du -h --max-depth=1  

  4. Redmine 项目管理工具----完全攻略

    摘要: 此篇博客涉及 安装,插件修改,插件安装,代码显示,中文乱码,SVN配置等内容,几乎覆盖所有redmine基本功能. 本机环境: Redmine 版本: 3.2.0 本机环境: win7 64位 ...

  5. Sql语句里的递归查询

    Sql语句里的递归查询 SqlServer2005和Oracle 两个版本 以前使用Oracle,觉得它的递归查询很好用,就研究了一下SqlServer,发现它也支持在Sql里递归查询举例说明:Sql ...

  6. python 遗传算法精简版

    精简版遗传算法,算法中仅采用变异算子而没有使用交叉算子,但是进化依然很有效 from string import ascii_lowercase from random import choice, ...

  7. Linux(9.28-10.4)学习笔记

    三种数字表示 无符号数: 基于传统的二进制表示法,表示大于或者等于零的数字. 补码(有符号数): 表示有符号数整数的最常见的方式,有符号数就是只可 以为正或者为负的数. 浮点数: 表示实数的科学计数法 ...

  8. 信息安全系统设计基础实验一:Linux开发环境的配置和使用

    北京电子科技学院(BESTI) 实验报告 课程:信息安全系统设计基础    班级:1353 姓名:芦畅 傅冬菁 学号:20135308 20135311 成绩:       指导教师:娄家鹏      ...

  9. php模式设计之 适配器模式

    在这个有没有对象都要高呼“面向对象”的年代,掌握面向对象会给我们带来意想不到的方便.学编程的小伙伴从开始能写几行代码实现简单功能到后来懂得将一些重复的操作组合起来形成一个“函数”,再到后来将“函数”和 ...

  10. asp.net Core开启全新的时代,用视频来告诉你,学习就是这么SO easy。

    https://channel9.msdn.com/Blogs/NET-Core/What-is-NET-Core 系统大家多发布一些视频的资料,学习起来更方便!我看到很多人发布的博客里面有的时候对于 ...