[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 ...
随机推荐
- synchronized(5)修饰语句块之:synchronized(XXX.class)
synchronized(XXX.class)有两种写法 synchronized(XXX.class)或者synchronized(obj.getClass()) Class也是一个类xxx.cla ...
- XmlDocument
XmlDocument增删改查. using System; using System.Collections.Generic; using System.ComponentModel; using ...
- (五)SpringIoc之Bean的作用域
此文转自 https://blog.csdn.net/icarus_wang/article/details/51586776# 有状态bean和无状态bean请看 https://blog.csdn ...
- STM32 (基础语法)笔记
指针遍历: char *myitoa(int value, char *string, int radix){ int i, d; int flag = 0; char *ptr = string; ...
- jmeter 连接 sqlite 进行压力测试
- ORM-PetaPoco
PetaPoco有以下特色:--------------------------20170715姜彦 微小,没有依赖项……单个的C#文件可以方便的添加到任何项目中. 工作于严格的没有装饰的Poco类, ...
- 洛谷 P1569 [USACO11FEB]属牛的抗议Generic Cow Prote…
题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cow ...
- ascii - 在八进制,十进制,十六进制中的 ASCII 字符集编码
描述 ASCII 是美国对于信息交换的标准代码,它是7位码,许多8位码(比如 ISO 8859-1, Linux 的默认字符集)容纳 ASCII 作为它们的下半部分.对应的国际 ASSII 是 ISO ...
- AUSU 安装Win10注意事项
Win10 U盘原版安装 安装前在电脑店PE里用DiskGenius分区分区表类型:GUID勾选:创建新ESP分区 . 创建MSR分区 安装必须使用UEFI引导和GPT硬盘,否则会提示无法安装Win1 ...
- CAD参数绘制半径标注(com接口)
主要用到函数说明: _DMxDrawX::DrawDimRadial 绘制一个半径标注.详细说明如下: 参数 说明 DOUBLE dCenterX 被标注的曲线的中点X值 DOUBLE dCenter ...