题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A;

思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N;

题目链接:传送门

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=5e3+,M=2e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; string a,b,c;
unsigned int ma[N][N],mc[N][N];
int check(int l1,int r1,int l2,int r2,int l3,int r3)
{
int s=,e=r1-l1;
if(ma[s][e]!=mc[l1][r1])return ;
s=e+,e=s+r2-l2;
if(ma[s][e]!=mc[l2][r2])return ;
s=e+,e=s+r3-l3;
if(ma[s][e]!=mc[l3][r3])return ;
return ;
}
void output(int l1,int r1,int l2,int r2,int l3,int r3)
{
for(int i=l1;i<=r1;i++)
printf("%c",b[i]);
printf("\n");
for(int i=l2;i<=r2;i++)
printf("%c",b[i]);
printf("\n");
for(int i=l3;i<=r3;i++)
printf("%c",b[i]);
printf("\n");
}
int main()
{
cin>>a>>b;
int n=a.size();c="";
for(int i=;i<n;i++)
if(a[i]>='A'&&a[i]<='Z')a[i]=a[i]-'A'+'a';
for(int i=;i<n;i++)
if(b[i]>='A'&&b[i]<='Z')c+=b[i]-'A'+'a';
else c+=b[i];
int tot=;
for(int i=;i<n;i++)
{
unsigned int seed = ; // 31 131 1313 13131 131313 etc..
unsigned int has= ;
for(int j=i;j<n;j++)
{
has=has*seed+(a[j]);
ma[i][j]=(has & 0x7FFFFFFF);
}
}
for(int i=;i<n;i++)
{
unsigned int seed = ; // 31 131 1313 13131 131313 etc..
unsigned int has= ;
for(int j=i;j<n;j++)
{
has=has*seed+(c[j]);
mc[i][j]=(has & 0x7FFFFFFF);
}
}
for(int i=;i<=n-;i++)
{
for(int j=i;j<=n-;j++)
{
if(check(,i-,i,j,j+,n-))
{
printf("YES\n");
output(,i-,i,j,j+,n-);
return ;
}
if(check(,i-,j+,n-,i,j))
{
printf("YES\n");
output(,i-,j+,n-,i,j);
return ;
}
if(check(i,j,,i-,j+,n-))
{
printf("YES\n");
output(i,j,,i-,j+,n-);
return ;;
}
if(check(i,j,j+,n-,,i-))
{
printf("YES\n");
output(i,j,j+,n-,,i-);
return ;;
}
if(check(j+,n-,,i-,i,j))
{
printf("YES\n");
output(j+,n-,,i-,i,j);
return ;
}
if(check(j+,n-,i,j,,i-))
{
printf("YES\n");
output(j+,n-,i,j,,i-);
return ;;
}
}
}
printf("NO\n");
return ;
}

codeforces gym 101164 K Cutting 字符串hash的更多相关文章

  1. codeforces gym 100971 K Palindromization 思路

    题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...

  2. Codeforces Gym 100338B Spam Filter 字符串哈希+贝叶斯公式

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  3. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  4. 【题解】 Codeforces Edu41 F. k-substrings (字符串Hash)

    题面戳我 Solution 我们正着每次都要枚举从长到短,时间复杂度承受不了,但是我们可以发现一个规律,假设某次的答案为\(x\),那么这个字符串为\(A+X+B\)组成,无论中间的\(X\)是重叠还 ...

  5. codeforces gym 100286 I iSharp (字符串模拟)

    题目链接 给定一个字符串.输入是int& a*[]&, b, c*; 输出是 int&&[]* a;int& b;int&* c; 输入格式里逗号后面一 ...

  6. Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面

    K - Cross SpiderTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  7. codeforces gym 100357 K (表达式 模拟)

    题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...

  8. Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )

    题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...

  9. CodeForces - 727E Games on a CD 字符串Hash

    题意:有n个单词,每个单词长度为k,顺时针将它们写成一个圆圈串.现在知道g个长度为k的单词,是否可以从这g个单词中选择n个形成这个圆圈串?如果有多个答案,任意输出一个. 思路 可以发现,如果枚举第一个 ...

随机推荐

  1. JustOj 2043: N!

    题目描述 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出,赛后我们会检查代码,如有发现,该位同学总分记0分处理) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把 ...

  2. P2800 又上锁妖塔

    P2800 又上锁妖塔  [温馨提示]使用仙术时飞过一层塔不花费时间,若爬过去,该层有多高,就要花费多长时间     我们可以用 f [ i ] 表示到达第 i 层时所用最短时间   到达第 i 层可 ...

  3. Kali linux vim使用命令笔记

    Kali Linux系统的vi编辑器/vim编辑器的使用和CentOS有很多不同.基本使用方法如下 1.vi的基本概念 基本上vi可以分为三种状态,分别是命令模式(command mode).插入模式 ...

  4. The Little Prince-11/28

    The Little Prince-11/28 Today I find some beautiful words from the book. You know -- one loves the s ...

  5. modelform添加属性

    暗暗啊

  6. python静态属性@property、类方法@classmethod、静态方法@staticmethod和普通方法

    静态属性:即将类的函数通过@property属性封装,封装后实例调用该函数时,不再需要在函数后面加(),而是用类似调用数据属性的方式直接调用函数名称即可执行函数. 静态属性既可以访问类的属性,也可以访 ...

  7. bzoj1663: [Usaco2006 Open]赶集

    Description Every year, Farmer John loves to attend the county fair. The fair has N booths (1 <= ...

  8. jquery获取包含本身的元素

    我们知道,使用jquery获取一个元素内的所有元素非常容易,使用jQuery.html()就可以. 如果是js语法的话,使用domObj.innerHTML也很容易实现. 那么问题来了,要想获取包涵节 ...

  9. RequestBody使用

    @RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的); GET方式无请求体,所以使用@RequestBody接收数据时,前端不能使用GET方式提交数据,而是 ...

  10. 15:element/Vue Admin

    1.1 简介 1.Vue Admin 简介 1. Vue Admin 是一个基于 Vue 2.0 & Bulma 0.3 的后台管理面板(管理系统),相当于是 Vue 版本的 Bootstra ...