题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6646

题意为求$a*10^{x}+b*10^{y}=c*10^{z}$满足公式的任意一组解$x,y,z$。

因为c有可能会由$a+b$进位得到,所以先在c后添加0使得c长度最长,然后先固定a的长度为c-1或c,遍历b的长度为b到c。

用hash判断是否相等。再交换b和a的顺序再判断一次。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
struct hash {
int base, mod;
int tot, Hash[maxn], xp[maxn];
hash() {
tot = ; xp[] = ; base = ; mod = 1e9 + ;
}
void init() { tot = ; }
void insert(int c) {
tot++;
Hash[tot] = (1LL * Hash[tot - ] * base + c) % mod;
xp[tot] = (1LL * xp[tot - ] * base) % mod;
}
int query(int l, int r) {
if (l == ) return Hash[r];
return (Hash[r] - (1LL * Hash[l - ] * xp[r - l + ] % mod) + mod) % mod;
}
friend bool check(hash &a, int l1, int r1, hash &b, int l2, int r2, hash &c, int l3, int r3) {
if ((a.query(l1, r1) + b.query(l2, r2)) % a.mod != c.query(l3, r3)) return false;
return true;
} }h[];
char a[][maxn];
int len[], oldlen[];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%s%s%s", a[] + , a[] + , a[] + );
for (int i = ; i <= ; i++)
oldlen[i] = len[i] = strlen(a[i] + ), h[i].init();
for (int i = ; i <= ; i++)
for (int j = ; j <= len[i]; j++)
h[i].insert(a[i][j] - '');
int x = , y = , z = ;
while (len[] <= max(len[], len[]) + ) {
z++;
a[][++len[]] = '';
h[].insert();
}
while (len[] < len[]) {
a[][++len[]] = '';
h[].insert();
}
while (len[] < len[]) {
a[][++len[]] = '';
h[].insert();
}
int f = ;
for (int i = oldlen[]; i <= len[] && f; i++) {
if (check(h[], , i, h[], , len[] - , h[], , len[])) {
f = ;
x = i - oldlen[], y = len[] - - oldlen[];
break;
}
if (check(h[], , i, h[], , len[], h[], , len[])) {
f = ;
x = i - oldlen[], y = len[] - oldlen[];
break;
}
}
for (int i = oldlen[]; i <= len[] && f; i++) {
if (check(h[], , len[] - , h[], , i, h[], , len[])) {
f = ;
x = len[] - - oldlen[], y = i - oldlen[];
break;
}
if (check(h[], , len[], h[], , i, h[], , len[])) {
f = ;
x = len[] - oldlen[], y = i - oldlen[];
break;
}
}
if (f)
printf("-1\n");
else
printf("%d %d %d\n", x, y, z);
}
}

[2019杭电多校第七场][hdu6646]A + B = C(hash)的更多相关文章

  1. 2019杭电多校第七场 HDU - 6656 Kejin Player——概率&&期望

    题意 总共有 $n$ 层楼,在第 $i$ 层花费 $a_i$ 的代价,有 $pi$ 的概率到 $i+1$ 层,否则到 $x_i$($x_i \leq 1$) 层.接下来有 $q$ 次询问,每次询问 $ ...

  2. [2019杭电多校第七场][hdu6656]Kejin Player

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意为从i级花费a元有p的概率升到i+1级,有1-p的概率降到x级(x<i),查询从L级升 ...

  3. [2019杭电多校第七场][hdu6655]Just Repeat

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 题意是说两个人都有一些带有颜色的牌,两人轮流出牌,但是不能出对面出过的颜色的牌,最后谁不能出牌谁 ...

  4. [2019杭电多校第七场][hdu6651]Final Exam

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6651 题意:n个科目,总共m分,通过一科需要复习花费科目分数+1分钟,在不知道科目分数的情况下,问最少 ...

  5. 杭电多校第七场 1010 Sequence(除法分块+矩阵快速幂)

    Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your ...

  6. 杭电多校第七场-J-Sequence

    题目描述 Let us define a sequence as belowYour job is simple, for each task, you should output Fn module ...

  7. hdu61272017杭电多校第七场1008Hard challenge

    Hard challenge Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  8. 2017杭电多校第七场1011Kolakoski

    Kolakoski Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Tota ...

  9. 2017杭电多校第七场1005Euler theorem

    Euler theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

随机推荐

  1. SQL查询优化的步骤

    一.定位慢查询 SQL优化的一般步骤:先查询mysql数据库运行状况,然后定位慢查询,再分析sql的执行过程,然后进行优化 1.使用show status查询数据库的运行状况 //显示数据库运行状态 ...

  2. SpringBoot之集成数据库

    一.集成 MySQL 数据库 1.1 配置 MySQL 添加依赖 <dependencies> <!--Spring 数据库相关依赖--> <dependency> ...

  3. vue组件学习(二)

    父子组件之间的数据传递, 父传给子: 直接在组件上传,如:<count :number="2"> (冒号和不要冒号的区别,有冒号会自动转为相应的类型)在名为count的 ...

  4. RSA和AES工具类

    AESUtil import com.xxx.common.BssException; import com.xxx.common.constants.CommonConstants; import ...

  5. linux运维、架构之路-SSH远程管理服务

    一.SSH服务功能介绍 1.远程登录管理 提供类似telnet远程联机服务器的服务,即上面提到的SSH服务 2.远程传输文件 是类似FTP服务的sftp-server,借助SSH协议来传输数据的,提供 ...

  6. opencv_python_基本图像处理

    https://www.e-learn.cn/content/python/2694135 https://blog.csdn.net/Eastmount/article/details/817488 ...

  7. CSP-S2 Review: 模拟

    Luogu 1087 FBI tree #include <cstdio> #include <cstring> char s[4100]; int n; char fbi(i ...

  8. layer系列之弹层layer.prompt

    layer官网:https://www.layui.com/doc/modules/layer.html layer在线调试:http://layer.layui.com/ 如何使用layer.pro ...

  9. spoj 3267 D-query

    题目链接:http://vjudge.net/problem/SPOJ-DQUERY --------------------------------------------------------- ...

  10. iptables List the rules in a chain or all chains

    [root@e ~]# iptables -hiptables v1.4.21 Usage: iptables -[ACD] chain rule-specification [options] ip ...