[luoguP2957] [USACO09OCT]谷仓里的回声Barn Echoes(Hash)
团队里的hash水题,数据小的不用hash都能过。。
也就是前缀hash,后缀hash,再比较一下就行。
——代码
#include <cstdio>
#include <cstring>
#define ULL unsigned long long int n, m, ans;
char s1[], s2[];
ULL base[], sum1[], sum2[], bit1[], bit2[]; inline int max(int x, int y)
{
return x > y ? x : y;
} inline int min(int x, int y)
{
return x < y ? x : y;
} int main()
{
int i;
s1[] = s2[] = '';
scanf("%s %s", s1 + , s2 + );
n = strlen(s1);
m = strlen(s2);
base[] = ;
for(i = ; i < max(n, m); i++) base[i] = base[i - ] * ;
for(i = ; i < n; i++) sum1[i] = sum1[i - ] * + s1[i];
for(i = ; i < m; i++) sum2[i] = sum2[i - ] * + s2[i];
for(i = n - ; i >= ; i--) bit1[i] = bit1[i + ] + s1[i] * base[n - - i];
for(i = m - ; i >= ; i--) bit2[i] = bit2[i + ] + s2[i] * base[m - - i];
for(i = ; i < min(n, m); i++)
if(sum1[i] == bit2[m - i] || sum2[i] == bit1[n - i])
ans = i;
printf("%d\n", ans);
return ;
}
[luoguP2957] [USACO09OCT]谷仓里的回声Barn Echoes(Hash)的更多相关文章
- 洛谷 2957 [USACO09OCT]谷仓里的回声Barn Echoes
题目描述 The cows enjoy mooing at the barn because their moos echo back, although sometimes not complete ...
- 洛谷——P2957 [USACO09OCT]谷仓里的回声Barn Echoes
https://www.luogu.org/problem/show?pid=2957 题目描述 The cows enjoy mooing at the barn because their moo ...
- [USACO09OCT]谷仓里的回声Barn Echoes(hush、STL)
https://www.luogu.org/problem/P2957 题目描述 The cows enjoy mooing at the barn because their moos echo b ...
- [USACO17JAN]Building a Tall Barn建谷仓
题目描述 Farmer John is building a brand new, NNN -story barn, with the help of his KKK cows ( 1≤N≤K≤101 ...
- 3409: [Usaco2009 Oct]Barn Echoes 牛棚回声
3409: [Usaco2009 Oct]Barn Echoes 牛棚回声 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 57 Solved: 47[ ...
- [luoguP3606] [USACO17JAN]Building a Tall Barn建谷仓(贪心 + 线段树)
传送门 把线段都读进来然后排序,先按右端点为第一关键字从小到大排序,后按左端点为第二关键字从小到大排序. 注意不能先按左端点后按右端点排序,否则会出现大包小的情况,如下: —————— ——— — ...
- 洛谷P3066 [USACO12DEC]逃跑的Barn (线段树合并)
题目描述It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to ro ...
- 洛谷P3066 [USACO12DEC] 逃跑的Barn [左偏树]
题目传送门 逃跑的Barn 题目描述 It's milking time at Farmer John's farm, but the cows have all run away! Farmer J ...
- 洛谷 P5542 [USACO19FEB]Painting The Barn
题目传送门 解题思路: 二维差分的板子题.题解传送门 AC代码: #include<iostream> #include<cstdio> using namespace std ...
随机推荐
- Struts2 表单提交与execute()方法的结合使用
1.创建web项目,添加struts2支持的类库,在web.xml中配置struts2过滤器. 2.创建名为UserAction的Action对象,并在其中编写execute()方法,代码如下所示: ...
- C. Hongcow Builds A Nation 并查集
http://codeforces.com/contest/745/problem/C 把他们并查集后, 其他没有连去government的点,全部放去同一个并查集,然后选择一个节点数最多的gover ...
- Xml学习笔记(1)
不同的xml文档构可能要用到不同的方法进行解析这里用到的是例如<student name="张三" id="1" sex="男"/&g ...
- ORM-PetaPoco
PetaPoco有以下特色:--------------------------20170715姜彦 微小,没有依赖项……单个的C#文件可以方便的添加到任何项目中. 工作于严格的没有装饰的Poco类, ...
- 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...
- 自己编辑Nuget拓展包,并发布Nuget服务器,提供下载使用
1. 在NuGet官网上注册并获取API Key 到NuGet上注册一个新的账号,然后在My Account页面,获取一个API Key,如果没有则在API keys 页面创建一个就可以. 2. 下载 ...
- Android(java)学习笔记188:学生信息管理系统案例(SQLite + ListView)
1.首先说明一个知识点,通常我们显示布局文件xml都是如下: setContentView(R.layout.activity_main): 其实每一个xml布局文件就好像一个气球,我们可以使用Vie ...
- python中统计计数的几种方法和Counter的介绍
使用字典dict()alist=['a','b','a','c','b','b',1,3]count_dict = dict()for i in alist:count_dict[i]=count_d ...
- sql中递归查询
with AA as ( select * from tb_ClientBranch_Category where BRANCH_MOM_NAME='北京易华录信息技术股份有限公司' union al ...
- gitlab数据迁移到docker容器
需求:想把服务器上的gitlab迁移到docker容器里面注意:gitlab的迁移,必须保持gitlab的版本一致,此处使用的是:8.4.3,数据库版本和类型一致,此处使用的是postgresql 9 ...