[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) ...
随机推荐
- 【串线篇】spring boot使用外置的Servlet容器
嵌入式Servlet容器:应用打成可执行的jar 优点:简单.便携: 缺点:默认不支持JSP.优化定制比较复杂 (使用定制器[ServerProperties/自定义EmbeddedServletCo ...
- 一、MyBatis基本使用,包括xml方式、注解方式、及动态SQL
一.简介 发展历史:MyBatis 的前 身是 iBATIS.最初侧重于 密码软件的开发 , 后来发展成为一款基于 Java 的持久层框架. 定 位:MyBatis 是一款优秀的支持自定义 ...
- 【BZOJ3601】一个人的数论
题目链接 题意简述 求小于 n 且与 n 互质的数的 k 次方之和. Sol 要求的东西: \[\sum_{i=1}^n i^k [gcd(i,n)=1]\] 枚举 gcd 上个莫比乌斯函数: \[\ ...
- layui数据表格,当数据过长出现三个...的时候,点击会弹出一个框全部显示,如何去掉这个框
最笨的方法就是通过css把那个框隐藏掉 .layui-table-tips-main{display:none} .layui-table-tips-c{display:none}
- Task7.手写数字识别
用PyTorch完成手写数字识别 import numpy as np import torch from torch import nn, optim import torch.nn.functio ...
- delphi exec error 错误处理
有时引用了三方jar后报错 [Exec Error] The command "PATH ..."" exited with code 1 解决方法 1.检测jar文件路 ...
- JavaScript变量和字面量
一.什么是变量? 首先了解一下什么是内存:内存就是保存程序在运行过程中,所需要用到的数据8bit(比特是表示信息的最小单位). 8bit=1byte 1024byte=1MB 1024MB=1GB 1 ...
- js数字每3位加一个逗号
if(typeof val ==="number"){ var str = val.toString(); ? /(\d)(?=(\d{})+\.)/g : /(\d)(?=(?: ...
- 批量下载文件web
最近需要这个所以写了一个例子一般批量下载由以下步骤组成: 1.确定下载的源文件位置 2.对文件进行打包成临时文件,这里会用到递归调用,需要的嵌套的文件夹进行处理,并返回文件保存位置 3.将打包好的文件 ...
- 一本通例题埃及分数—题解&&深搜的剪枝技巧总结
一.简述: 众所周知,深搜(深度优先搜索)的时间复杂度在不加任何优化的情况下是非常慢的,一般都是指数级别的时间复杂度,在题目严格的时间限制下难以通过.所以大多数搜索算法都需要优化.形象地看,搜索的优化 ...