[2019杭电多校第七场][hdu6646]A + B = C(hash)
题目链接: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)的更多相关文章
- 2019杭电多校第七场 HDU - 6656 Kejin Player——概率&&期望
题意 总共有 $n$ 层楼,在第 $i$ 层花费 $a_i$ 的代价,有 $pi$ 的概率到 $i+1$ 层,否则到 $x_i$($x_i \leq 1$) 层.接下来有 $q$ 次询问,每次询问 $ ...
- [2019杭电多校第七场][hdu6656]Kejin Player
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意为从i级花费a元有p的概率升到i+1级,有1-p的概率降到x级(x<i),查询从L级升 ...
- [2019杭电多校第七场][hdu6655]Just Repeat
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 题意是说两个人都有一些带有颜色的牌,两人轮流出牌,但是不能出对面出过的颜色的牌,最后谁不能出牌谁 ...
- [2019杭电多校第七场][hdu6651]Final Exam
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6651 题意:n个科目,总共m分,通过一科需要复习花费科目分数+1分钟,在不知道科目分数的情况下,问最少 ...
- 杭电多校第七场 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 ...
- 杭电多校第七场-J-Sequence
题目描述 Let us define a sequence as belowYour job is simple, for each task, you should output Fn module ...
- hdu61272017杭电多校第七场1008Hard challenge
Hard challenge Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) ...
- 2017杭电多校第七场1011Kolakoski
Kolakoski Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Tota ...
- 2017杭电多校第七场1005Euler theorem
Euler theorem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) ...
随机推荐
- 使用QT创建系统托盘
使用QT来创建一个系统托盘,事实上是一件很简单的事.为什么这么说?一是因为QT文档给出了比较详细的例子,二是QT的结构比较优雅,设计风格统一.但是在动手之前,我们要从哪里下手?虽然QT文档给出了一个比 ...
- Kafka---系统学习
1.Topics 1.1.Topic 就是 数据主题: 1.2.作用:数据记录 发布的地方,用来 区分 业务系统: 1.3.每个Topic 可以有多个 消费者 订阅它的数据: 1.4.每个T ...
- twint 安装及使用
分享这个post是自己方便查,还有中文网界对这个东西介绍太少. 更多的就看github项目twint吧. Installation: git+pip3: git clone https://githu ...
- SonarQube规则之漏洞类型
漏洞类型: 1."@RequestMapping" methods should be "public"漏洞 阻断标注了RequestMapping是contr ...
- 分布式事务 GTS 的价值和原理浅析
GTS 今年双 11 的成绩 今年 2684 亿的背后,有一个默默支撑,低调到几乎被遗忘的中间件云产品——GTS(全局事务服务,Global Transaction Service),稳稳地通过了自 ...
- setData 机制
解释:setData 函数,用于将数据,从逻辑层发送到视图层,当开发者调用 setData 后,数据的变化,会引起视图层的更新.参数说明 属性 类型 是否必填 描述 data Object 是 这次要 ...
- sift特征点检测和特征数据库的建立
类似于ORBSLAM中的ORB.txt数据库. https://blog.csdn.net/lingyunxianhe/article/details/79063547 ORBvoc.txt是怎么 ...
- HDU6599 (字符串哈希+回文自动机)
题意: 求有多少个回文串的前⌈len/2⌉个字符也是回文串.(两组解可重复)将这些回文串按长度分类,分别输出长度为1,2,...,n的合法串的数量. 题解:https://www.cnblogs.co ...
- WIN7系统JavaEE(java+tomcat7+Eclipse)环境配置
https://jingyan.baidu.com/article/3a2f7c2e62d25e26afd611fa.html WIN7系统JavaEE(java+tomcat7+Eclipse)环境 ...
- 二十六、python中json学习
1.json序列介绍:提供4个关键字:dumps,dump,loads,load(与pickle用法完全相同) 语法:f.write(bytes(json.dumps(dict),encoding=& ...