[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 ...
随机推荐
- Linux环境下SolrCloud集群环境搭建关键步骤
Linux环境下SolrCloud集群环境搭建关键步骤. 前提条件:已经完成ZooKeeper集群环境搭建. 一.下载介质 官网下载地址:http://www.apache.org/dyn/close ...
- 利用Marshal.AllocHGlobal申请非托管内存,unsafe代码
unsafe public class RUN { int[] array3; IntPtr handle; ; public RUN() { handleCount = * ; handle = S ...
- 员工管理系统(集合与IO流的结合使用 beta5.0 BufferedReader/ BufferedWriter)
package cn.gee; public class Emp { private String id;//员工编号 一般是唯一的 private String sname; private int ...
- 442 Find All Duplicates in an Array 数组中重复的数据
给定一个整数数组 a,其中1 ≤ a[i] ≤ n (n为数组长度), 其中有些元素出现两次而其他元素出现一次.找到所有出现两次的元素.你可以不用到任何额外空间并在O(n)时间复杂度内解决这个问题吗? ...
- ZOJ 3605Find the Marble(dp)
ZOJ 3605 大体意思就是 找出随机选了K个交换后 石子在第i个罐子里的概率最大 也就是可能的总数最大 这样就可以写出递推方程 dp[i][j][k] += dp[i-1][e][k]; (0&l ...
- .net 字符串和JSON格式的互换
近期又做了个问卷调查,问卷调查一次性要保存一二十个题目和答案!所以嘞,博主为了偷懒,就直接把答卷内容保存成了Json格式! 好处当然是很多啦! 只需一个字段就能保存整个答卷的内容! 想想都刺激!哈哈~ ...
- 工作记录:JS正则表达式 angularjs ng-if ng-show ng-switch
用了一下JS 正则表达式判断密码,很简单 学习了angularjs的ng-if ng-show ng-switch的区别并使用 https://www.cnblogs.com/54td/p/59743 ...
- 5.1点击4个按钮显示相应的div
事件:onclick 属性:display,className 用到for语句,index标记,this当前事件 先清空后附加 <!DOCTYPE html><html>< ...
- Jauery 中Ajax的几种异步请求
以下介绍Jquery中 Post Get Ajax几种异步请求的使用方法 <%@ Page Language="C#" AutoEventWireup=&q ...
- SQL Server xtype的介绍
sysobjects 表 在数据库内创建的每个对象(约束.默认值.日志.规则.存储过程等)在表中占一行.只有在 tempdb 内,每个临时对象才在该表中占一行. 列名 数据类型 描述 name sys ...