Restoring the Expression
题目地址:http://codeforces.com/problemset/problem/898/F
A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character ‘+’ and one character ‘=’ should be inserted into given sequence of digits so that:
character’+’ is placed on the left of character ‘=’,
characters ‘+’ and ‘=’ split the sequence into three non-empty subsequences consisting of digits (let’s call the left part a, the middle part — b and the right part — c),
all the three parts a, b and c do not contain leading zeros,
it is true that a+b=c.
It is guaranteed that in given tests answer always exists.
Input
The first line contains a non-empty string consisting of digits. The length of the string does not exceed 106.
Output
Output the restored expression. If there are several solutions, you can print any of them.
Note that the answer at first should contain two terms (divided with symbol ‘+’), and then the result of their addition, before which symbol’=’ should be.
Do not separate numbers and operation signs with spaces. Strictly follow the output format given in the examples.
If you remove symbol ‘+’ and symbol ‘=’ from answer string you should get a string, same as string from the input data.
题意:已知一个顺序排好的数字字符串,每位都是十进制,要求给原串进行分割,加入‘+’和‘=’,使字符串成为"a+b=c"的形式。
理解:使用哈希表,任意一个子串都映射成一个数字,然后就是怎样去凑a+b=c的形式,无非就是四种情况。
- len_a = len_c
- len_a + 1 = len_c
- len_b = len_c
- len_b + 1 = len_c
然后再写个check函数对每个函数检验是否成立就好了。
ac代码如下:
#include<iostream>
#include<string>
using namespace std;
#define mod 1000000007
#define ll long long
#define maxn 1000005
char s[maxn];
ll bat = 10;
ll hashh[maxn];
int len;
ll Qpow(ll a, ll b, ll p) //快速幂
{
ll ans = 1;
while (b > 0)
{
if (b & 1) ans

最低0.47元/天 解锁文章
1211

被折叠的 条评论
为什么被折叠?



