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. 第20章 DLL高级技术(2)

    20.3 延迟载入DLL 20.3.1延迟载入的目的 (1)如果应用程序使用了多个DLL,那么它的初始化可能比慢,因为加载程序要将所有必需的DLL映射到进程的地址空间.→利用延迟加载可将载入过程延伸到 ...

  2. 用uGUI开发自定义Toggle Slider控件

    一.前言 写完<Unity4.6新UI系统初探>后,我模仿手机上的UI分别用uGui和NGUI做了一个仅用作演示的ToggleSlider,我认为这个小小的控件已能体现自定义控件的开发过程 ...

  3. Unity键值(KeyCode)

    Unity的Input管理 keyCode示例 keyCode Demo function OnGUI(){ var e:Event=Event.current; if(e.isKey){ Debug ...

  4. java9-9 匿名内部类

    1. 匿名内部类 就是内部类的简化写法. 前提:存在一个类或者接口 这里的类可以是具体类也可以是抽象类. 格式: new 类名或者接口名(){ 重写方法; } new Xxx()是创建了一个对象,而抽 ...

  5. Dvwa writeup

    DVWA(Dam vulnerable Web Application)是使用PHP+Mysql编写的一套用于常规漏洞教学和漏洞挖掘的一个测试学习程序,在此程序中包含了常见的web方面的漏洞,如命令行 ...

  6. EventBus (三) 源码解析 带你深入理解EventBus

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/40920453,本文出自:[张鸿洋的博客] 上一篇带大家初步了解了EventBus ...

  7. 浅析C#深拷贝与浅拷贝(转)

    1.深拷贝与浅拷贝   拷贝即是通常所说的复制(Copy)或克隆(Clone),对象的拷贝也就是从现有对象复制一个“一模一样”的新对象出来.虽然都是复制对象,但是不同的 复制方法,复制出来的新对象却并 ...

  8. XCode的 Stack Trace,调试时抛出异常,定位到某一行代码

    在Xcode调试程序的时候,总是会出现不知道错误在什么地方的问题,很是捉急,现在又一个办法,可以具体定位到错误行的代码,试一下吧?超级好用 操作很简单: 1.在XCode界面中按cmd + 6快捷键, ...

  9. C#文件和文件文件夹按时间、名称排序-顺序与倒序

    对于文件和文件夹有多种排序方式,常用的就是按创建或修改时间.按文件名排序.在 C# 中,按时间和文件名排序都十分简单,用数组提供的排序方法 Array.Sort() 一行代码就可以搞定,当然也可以用常 ...

  10. 封装WCF客户端调用

    在之前的博客中,我记录过如何利用SvcUtil.exe工具生成客户端的代理文件,然后调用的情形. 今天我要讲解的是利用代码直接对服务端进行调用.好处在于,一是不会生成那么大的引用文件,其次是可以方便控 ...