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. Spring MVC之cookies跟session 数据绑定

    在我最早接触web开发的中学时代,学习的asp技术对于session的概念其实很清楚 Session("username")="张三"下次要用的时候,直接用se ...

  2. 梳理git分支管理策略

    如果你严肃对待编程,就必定会使用"版本管理系统"(Version Control System). 眼下最流行的"版本管理系统",非Git莫属. 相比同类软件, ...

  3. 使用CSS3画出一个叮当猫

    刚学习了这个案例,然后觉得比较好玩,就练习了一下.然后发现其实也不难,如果你经常使用PS或者Flash的话,应该就会知道画个叮当猫是很容易的事,至少我是这么觉得.但是,用CSS3画出来确实是第一次接触 ...

  4. Go Walk教程 - 流程控制( switch)

    Go的 switch 非常灵活,表达式不必是常量或整数,执行的过程从上至下,直到找到匹配项,不要break: var score =98 var result string switch score/ ...

  5. Word Ladder 未完成

    Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...

  6. 修改Tomcat可支持get形式url长度

    maxHttpHeaderSize="8192" 加在 <Connector port="8081" maxHttpHeaderSize="31 ...

  7. matlab figure 窗口最大化

    http://blog.163.com/yinhexiwen@126/blog/static/6404826620122942057214/ % figure 窗口最大化,坐标轴也随着窗口变大而相应变 ...

  8. Android -- Properties使用

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; public ...

  9. [CareerCup] 3.5 Implement Queue using Two Stacks 使用两个栈来实现队列

    3.5 Implement a MyQueue class which implements a queue using two stacks. LeetCode上的原题,请参见我之前的博客Imple ...

  10. Struts2 面试题分析

    1. 简述 Struts2 的工作流程: ①. 请求发送给 StrutsPrepareAndExecuteFilter ②. StrutsPrepareAndExecuteFilter 判定该请求是否 ...