2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Barty's Computer(暴力+hash)
来源:互联网 发布:数据泄密如何防止拍照 编辑:程序博客网 时间:2024/06/16 17:24
Barty have a computer, it can do these two things.
Add a new string to its memory, the length of this string is even.
For given 4 strings a,b,c,d, find out how many strings that can be product by a+s1+b+c+s2+d, and ∣a∣+∣s1∣+∣b∣=∣c∣+∣s2∣+∣d∣. ∣s∣ means the length of string s, s1 and s2 can be any string, including
""
.
Please help your computer to do these things.
Input Format
Test cases begins with T(T≤5).
Then T test cases follows.
Each test case begins with an integer Q(Q≤30000).
Then Q lines,
1 s: add a new string s to its memory.
2 a b c d: find how many strings satisfying the requirement above.
∑∣s∣+∣a∣+∣b∣+∣c∣+∣d∣≤2000000.
Output Format
For type 2 query. Output the answer in one line.
样例输入
1101 abcqaq1 abcabcqaqqaq2 ab bc qa aq2 a c q q1 abcabcqaqqwq2 ab bc qa aq2 a c q q1 abcq2 a c q q2 a b c q
样例输出
121331
解:因为题目没有明确给出字符串的个数与长度 所以这里我们开一个长整型指针数组避免越界
一开始逐个字符匹配T了 所以加了hash预处理
坑点 并不是文本串的总长度大于4个字符串的总长度就可以 需要前两个 和 后两个字符串的长度总和小于等于 文本串的一半
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>using namespace std;const int N = 1e6+10;typedef long long LL;char str[N], a[N], b[N], c[N], d[N];const LL mod = 1e9+7;const LL seed = 1313;LL *hash1[N], pos[N];int xlen[N];int main(){ pos[0]=1; for(int i=1;i<N;i++) pos[i]=pos[i-1]*seed%mod; int t; scanf("%d", &t); while(t--) { int n; scanf("%d",&n); int h=0; while(n--) { int xx; scanf("%d", &xx); if(xx==1) { scanf("%s",str+1); int l=strlen(str+1); xlen[h]=l; hash1[h]=new LL[l+3]; hash1[h][0]=0; for(int i=1;i<=l;i++) hash1[h][i]=(hash1[h][i-1]*seed%mod+(str[i]-'a'+1))%mod; h++; } else { scanf("%s %s %s %s",a+1,b+1,c+1,d+1); int l1=strlen(a+1),l2=strlen(b+1),l3=strlen(c+1),l4=strlen(d+1); int sum=l1+l2+l3+l4, cnt=0; LL ans1=0, ans2=0, ans3=0, ans4=0; for(int j=1; j<=l1; j++) ans1=(ans1*seed%mod+(a[j]-'a'+1))%mod; for(int j=1; j<=l2; j++) ans2=(ans2*seed%mod+(b[j]-'a'+1))%mod; for(int j=1; j<=l3; j++) ans3=(ans3*seed%mod+(c[j]-'a'+1))%mod; for(int j=1; j<=l4; j++) ans4=(ans4*seed%mod+(d[j]-'a'+1))%mod; for(int i=0;i<h;i++) { if((xlen[i]&1)||l1+l2>xlen[i]/2||l3+l4>xlen[i]/2) continue; int cx=xlen[i]/2; LL x=hash1[i][l1]; if(x!=ans1) continue; x=(hash1[i][cx]-hash1[i][cx-l2]*pos[l2]%mod+mod)%mod; if(x!=ans2) continue; x=(hash1[i][cx+l3]-hash1[i][cx]*pos[l3]%mod+mod)%mod; if(x!=ans3) continue; x=(hash1[i][2*cx]-hash1[i][2*cx-l4]*pos[l4]%mod+mod)%mod; if(x!=ans4) continue; cnt++; } printf("%d\n",cnt); } } } return 0;}
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Barty's Computer(暴力+hash)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 I. Barty's Computer(哈希||字典树)
- 2017 ACM-ICPC西安赛区网络赛 Barty's Computer【哈希】
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 G Xor lca+暴力
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017西安邀请赛: I. Barty's Computer(暴力+Hash)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin
- 2017 ACM-ICPC 亚洲区(西安赛区)网络...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Trig Function(数据水,暴力+逆元)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(概率)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin(矩阵快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin(组合数)
- 【学习笔记七】
- JAVA RESTful WebService实战笔记(四)
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- Java数据结构之链表
- C++中调用main函数
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Barty's Computer(暴力+hash)
- 自定义配置数据源 DataSource
- Java之——内存溢出案例
- Iterator原理(jdk1.8)
- Java实现选择排序和冒泡排序
- 枚举法填运算符
- Java多线程看我这一篇就足够了
- JavaScript-2-2:DOM(重点),封装类
- 利用DOM实现图书馆管理系统