题目链接: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. computed 与methods , watched 的区别

    computed 与watched 的区别: 异步请求 数据变化 使用watched ,计算属性不支持异步 计算一个值的结果 用 computed computed 与methods的区别: comp ...

  2. CSS3边框 阴影 box-shadow

    box-shadow是向盒子添加阴影.支持添加一个或者多个. box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式]; 参数介绍: box-sh ...

  3. Django【第13篇】:Django之Form组件

    django 之知识点总结以及Form组件 一.model常用操作 1.13个API查询:all,filter,get ,values,values_list,distinct,order_by ,r ...

  4. Rails3:使用bundler管理gems

    Rails3:使用bundler管理gems bundler 是一套为了 Rails3 所打造的全新 Gem dependencies 管理工具:一套基于 Rubygems 的更高阶套件管理工具,适合 ...

  5. VUE+Ionic,项目搭建&打包成APK

    安装Vue&创建Vue工程 1.安装Vue CLI: npm install -g vue-cli 2.创建新的Vue项目,创建最后一步会提醒是否使用npm install 自动安装,如果选择 ...

  6. 多模字符串匹配算法-Aho–Corasick

    背景 在做实际工作中,最简单也最常用的一种自然语言处理方法就是关键词匹配,例如我们要对n条文本进行过滤,那本身是一个过滤词表的,通常进行过滤的代码如下 for (String document : d ...

  7. Mybatis 并发执行导致cpu占满的问题

    最近线上服务经常 出现cpu达到100%的问题,发现都是执行oracle操作的方法就没有返回.经过排查,最后定位到cpu消耗在以下方法 System.Collections.Generic.Dicti ...

  8. 2019年开发App记录

    Pod 制作私有库参考 https://www.jianshu.com/p/f903ecf8e882 Pod私有库的升级 改代码部分,到Example文件夹执行pod install ,修改XXX.s ...

  9. Java——super

    在Java类中使用super来引用基类的成分.   [代码]  

  10. noi 1700 + 1756 八皇后问题 x

    1700:八皇后问题 总时间限制:  10000ms 内存限制:  65536kB 描述 在国际象棋棋盘上放置八个皇后,要求每两个皇后之间不能直接吃掉对方. 输入 无输入. 输出 按给定顺序和格式输出 ...