【hdu 6208】The Dominator of Strings
【链接】h在这里写链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include<bits/stdc++.h>
using namespace std; const int N = 1e5;
const int SN = 2e2;
const int MAX_CHAR = 300;//每个数字的最大值。
int s[N + 10];//如果是数字,就写成int s[N+10]就好,从0开始存
int Sa[N + 10], T1[N + 10], T2[N + 10], C[N + 10], T;
int Height[N + 10], Rank[N + 10], idx[N + 10], in[N + 10], tag, L[N + 10], R[N + 10];
int Le[N + 10];
vector <string> vec;
bool flag[N + 10]; void build_Sa(int n, int m) {
int i, *x = T1, *y = T2;
for (i = 0; i<m; i++) C[i] = 0;
for (i = 0; i<n; i++) C[x[i] = s[i]]++;
for (i = 1; i<m; i++) C[i] += C[i - 1];
for (i = n - 1; i >= 0; i--) Sa[--C[x[i]]] = i;
for (int k = 1; k <= n; k <<= 1)
{
int p = 0;
for (i = n - k; i<n; i++) y[p++] = i;
for (i = 0; i<n; i++) if (Sa[i] >= k) y[p++] = Sa[i] - k;
for (i = 0; i<m; i++) C[i] = 0;
for (i = 0; i<n; i++) C[x[y[i]]]++;
for (i = 1; i<m; i++) C[i] += C[i - 1];
for (i = n - 1; i >= 0; i--) Sa[--C[x[y[i]]]] = y[i];
swap(x, y);
p = 1; x[Sa[0]] = 0;
for (i = 1; i<n; i++)
x[Sa[i]] = y[Sa[i - 1]] == y[Sa[i]] && y[Sa[i - 1] + k] == y[Sa[i] + k] ? p - 1 : p++;
if (p >= n) break;
m = p;
}
} bool contain(string &S, string T) {//最长的那个串和 短串
int l = 1, r = S.size(),temp = -1;
while (l <= r) {
int m = (l + r) >> 1;
if (S.compare(Sa[m], T.length(), T) <= 0)//如果后缀比S来的小。
{
temp = m;
l = m + 1;//可以再大一点
}
else
{
r = m - 1;
}
}
if (temp == -1)
return 0;
else
return S.compare(Sa[temp], T.length(), T) == 0;
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
int TT;
cin >> TT;
while (TT--) {
int T;
cin >> T;
int n = 0, ma = 0, idxma;
string ss;
vec.clear();
vec.push_back(" ");
for (int i = 1; i <= T; i++) {
cin >> ss;
vec.push_back(ss);
if ((int)ss.size() > ma) {
ma = (int)ss.size();
idxma = i;
}
}
for (int i = 0; i <= (int) vec[idxma].size() - 1; i++)
s[n++] = vec[idxma][i];
s[n] = 0;
build_Sa(n + 1, MAX_CHAR);//注意调用n+1
bool ok = true;
for (int i = 1; i <= T; i++)
if (idxma!=i){//不能是最大的那个,那个是要被匹配的。
if (!contain(vec[idxma], vec[i])) {
ok = false;
break;
}
}
if (ok) {
cout << vec[idxma] << endl;
}
else
cout << "No" << endl;
}
return 0;
}
【hdu 6208】The Dominator of Strings的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 2594】Simpsons’ Hidden Talents
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
随机推荐
- js call 和 apply
前言 call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的,换句话说,就是为了改变函数体内部 this 的指向. call 和 apply二者的作用完全一样,只是接 ...
- typeof 和 instanceof 的区别
在JavaScript中我们想得到一个变量的类型,我们一般会用typeof 得到这个类型的 字符串,但是对于引用类型,typeof始终会返回一个"object",在我们js中有十个 ...
- ubuntu下eclipse java ee首次打开提示找不到jdk的问题
最近想搭建一个本地服务器,方便写一些网络请求相关的demo,遂下载了eclipse ee版 ( IDEA证书好贵,暂时不想买-=-),下载---解压 一切正常,但是当在terminal下打开ecli ...
- 使用Spring实现MySQL读写分离(转)
使用Spring实现MySQL读写分离 为什么要进行读写分离 大量的JavaWeb应用做的是IO密集型任务, 数据库的压力较大, 需要分流 大量的应用场景, 是读多写少, 数据库读取的压力更大 一个很 ...
- LeetCode 06 ZigZag Conversion
https://leetcode.com/problems/zigzag-conversion/ 水题纯考细心 题目:依照Z字形来把一个字符串写成矩阵,然后逐行输出矩阵. O(n)能够处理掉 记i为行 ...
- js20---接口3种方式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- golang 部分理解:关于channel 和 goroutine 例子
部分理解:关于channel 和 goroutine 例子package main import "strconv" import "fmt" func mai ...
- spring基础内容
关注和收藏在这里 深入理解Spring框架的作用 纵览Spring , 读者会发现Spring 可以做非常多的事情. 但归根结底, 支撑Spring的仅仅是少许的基本理念, 所有的理念都可以追 ...
- CISP/CISA 每日一题 19
CISSP 每日一题(答)What determines how often an audit should be performed? Risk What policy requires u ...
- 【2017 Multi-University Training Contest - Team 7】Kolakoski
[Link]:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=765 [Description] 有一种 ...