题意:给你两个字符串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. Python进阶【第六篇】内置函数中好玩的几个(今天写的太水)

    zip()函数 两个参数一一对应,参数是序列类型,序列包括列表,元组,字符串,当两个序列不等长时,按公共最长部分匹配,形似“拉链”. max()和min()函数 以max()为例,min()类似,只是 ...

  2. Python进阶【第一篇】:Python简介

    Python简介 1.Python的由来 Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. 2.C 和 Python.Ja ...

  3. 输出链表中倒数第k个节点

    题目描述 输入一个链表,输出该链表中倒数第k个结点. struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x ...

  4. The logback manual #01# Introduction

    依赖包如下pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&qu ...

  5. alert.log中的minact-scn: useg scan erroring out with error e:376警告

    早上,开发说昨晚一台服务器的undo好像有异常,早上上去一看,库停了,正常startup之后,随手crud了一把,都正常.去看alert.log日志,发现undo某个数据块访问报I/O读错误,如下: ...

  6. 比beanutil更加灵活的dto转换工具dozer

    准确的说,是因为pojo无法一招走天下或者说内外部隔离的原因,所以有些时候,不得不在两个bean之间做copy或者转换映射.对于直接性的属性拷贝beanutil以及能够满足大部分要求,但是如果遇到字段 ...

  7. linux command wrap

    $ cat tmux-attach ] ; then tmux ls else tmux attach -t $ fi $ cat /usr/bin/cscope-go.sh #!/bin/bash ...

  8. OSI7层模型(TCP4层)

    OSI7层模型(TCP4层) 第一层:物理层 在局部局域网络上传送帧,它负责管理电脑通信设备和网络媒体之间的互通.包括了针脚.电压.线缆规范.集线器.中继器.网卡.主机适配器等. 第二层:数据链路层 ...

  9. Fedora 全局代理上网设置

    1.首先新建一个bash文件 vim /etc/profile.d/proxy.sh 加入以下内容 (有账号密码) export HTTP_PROXY="http://username:pa ...

  10. 20165310 NetSec Week4 Exp2 后门原理与实践

    20165310 NetSec Exp2后门原理与实践 一.基础问题 例举你能想到的一个后门进入到你系统中的可能方式? 网页木马等访问网页导致 下载非官方源软件 随意下载邮件中不明程序等 例举你知道的 ...