传送门

团队里的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)的更多相关文章

  1. 洛谷 2957 [USACO09OCT]谷仓里的回声Barn Echoes

    题目描述 The cows enjoy mooing at the barn because their moos echo back, although sometimes not complete ...

  2. 洛谷——P2957 [USACO09OCT]谷仓里的回声Barn Echoes

    https://www.luogu.org/problem/show?pid=2957 题目描述 The cows enjoy mooing at the barn because their moo ...

  3. [USACO09OCT]谷仓里的回声Barn Echoes(hush、STL)

    https://www.luogu.org/problem/P2957 题目描述 The cows enjoy mooing at the barn because their moos echo b ...

  4. [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 ...

  5. 3409: [Usaco2009 Oct]Barn Echoes 牛棚回声

    3409: [Usaco2009 Oct]Barn Echoes 牛棚回声 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 57  Solved: 47[ ...

  6. [luoguP3606] [USACO17JAN]Building a Tall Barn建谷仓(贪心 + 线段树)

    传送门 把线段都读进来然后排序,先按右端点为第一关键字从小到大排序,后按左端点为第二关键字从小到大排序. 注意不能先按左端点后按右端点排序,否则会出现大包小的情况,如下: —————— ———  — ...

  7. 洛谷P3066 [USACO12DEC]逃跑的Barn (线段树合并)

    题目描述It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to ro ...

  8. 洛谷P3066 [USACO12DEC] 逃跑的Barn [左偏树]

    题目传送门 逃跑的Barn 题目描述 It's milking time at Farmer John's farm, but the cows have all run away! Farmer J ...

  9. 洛谷 P5542 [USACO19FEB]Painting The Barn

    题目传送门 解题思路: 二维差分的板子题.题解传送门 AC代码: #include<iostream> #include<cstdio> using namespace std ...

随机推荐

  1. 题解报告:hdu 1229 还是A+B

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1229 Problem Description 读入两个小于10000的正整数A和B,计算A+B.需要注 ...

  2. mysqlshow(数据库对象查看工具)

    mysqlshow是mysql客户端对象查看工具,可以用来查看数据库.数据库中的表.表中的列.索引等. 1.mysqlshow命令的语法 shell > mysqlshow [options] ...

  3. 关于JTable的使用

    JTable是个JavaSwing中的表格控件,可以用来显示数据和编辑数据.这里讲一下我的使用心得. JavaSwing讲究MVC理念,而这个JTable也可以说是个迷你的MVC模型.JTable只是 ...

  4. TC 609DIV2(950)

    Problem Statement      Vocaloids Gumi, Ia, and Mayu love singing. They decided to make an album comp ...

  5. IIS中不让下级应用程序继承主域名的web.config配置

    <location path="." allowOverride="true" inheritInChildApplications="fals ...

  6. jq判断上下滚动

    $(document).ready(function(){ var p=0,t=0; $(window).scroll(function(e){ p = $(this).scrollTop(); if ...

  7. Vue.js语法糖整理

    el:element 需要获取的元素,一定是HTML中的根容器元素 data:用于数据的存储 methods:用于存储各种方法 数据绑定字面量只加载一次{{* msg}} data里面可以进行简单的运 ...

  8. vue2.0 路由传参(router-link传过去)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. .Net Core 真能令微软的.Net 跨平台“蔓延”?

    什么是.Net .Net 本身就是基于公共语言基础架构(CLI)实现的平台独立的公共语言开发平台,只是自2006年成为规范以来的CLI,只有Windows自己支持罢了(mono除外).微软的.Net ...

  10. [转载]迅为4418开发板Qt移植移动4G模块第一部分

        本文转自迅为论坛:http://topeetboard.com   平台:iTOP-4418开发板   1.首先要配置内核,这个一步和Android系统移植3G或者4G模块是一样的.一般模块的 ...