UVAL 7902 2016ECfinal F - Mr. Panda and Fantastic Beasts
题意:
给出n个串,求一个最短的第一个串的子串使它不在其他的n-1个串中出现,若有多个求字典序最小的。
Limits: • 1 ≤ T ≤ 42. • 2 ≤ N ≤ 50000. • N ≤ S1 + S2 + · · · + SN ≤ 250000. • the sum of Si in all test cases doesn’t exceed 3 × 106 .
Sample Input
3
2
aba
bab
3
qnu
cvbb
bnu
3
a
aa
aaa
Sample Output
Case #1: aba
Case #2: q
Case #3: Impossible
代码:
//这么多串肯定要把他们连接起来(之间用没出现的字符隔开)。后缀数组求出heigh数组,答案要求字典序最小所以后缀数组从前向后找即可,每找到
//一个在第一个串中的i位置时,在该位置向前和向后各找到第一个不在第一个串中的j那么lcp(i,j)一定是i位置和其他不在第一个串中后缀的
//最长的lcp,那么这个lcp+1的长度就一定是在其他串中没有出现过,要求字典序最小所以要向后扩展一位,并且这个长度不能超出第一个串。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=;
int t,n,sa[MAXN],he[MAXN],ra[MAXN],xx[MAXN],yy[MAXN],buc[MAXN];
char s[MAXN],ch[MAXN];
int len,len1,m;
void get_suf()
{
int *x=xx,*y=yy;
for(int i=;i<m;i++) buc[i]=;
for(int i=;i<len;i++) buc[x[i]=s[i]]++;
for(int i=;i<m;i++) buc[i]+=buc[i-];
for(int i=len-;i>=;i--) sa[--buc[x[i]]]=i;
for(int k=;k<=len;k<<=){
int p=;
for(int i=len-;i>=len-k;i--) y[p++]=i;
for(int i=;i<len;i++) if(sa[i]>=k) y[p++]=sa[i]-k;
for(int i=;i<m;i++) buc[i]=;
for(int i=;i<len;i++) buc[x[y[i]]]++;
for(int i=;i<m;i++) buc[i]+=buc[i-];
for(int i=len-;i>=;i--) sa[--buc[x[y[i]]]]=y[i];
swap(x,y);
p=;x[sa[]]=;
for(int i=;i<len;i++){
if(y[sa[i-]]==y[sa[i]]&&y[sa[i-]+k]==y[sa[i]+k])
x[sa[i]]=p-;
else x[sa[i]]=p++;
}
if(p>=len) break;
m=p;
}
for(int i=;i<len;i++) ra[sa[i]]=i;
int k=;
for(int i=;i<len;i++){
if(ra[i]==) { he[]=;continue; }
if(k) k--;
int j=sa[ra[i]-];
while(s[i+k]==s[j+k]&&i+k<len&&j+k<len) k++;
he[ra[i]]=k;
}
}
void solve()
{
int ans=len,pos=-;
for(int i=;i<len;i++){
while(i<len&&sa[i]>=len1) i++;
if(i>=len) break;
int plcp=he[i];
for(int j=i-;j>=;j--){
if(sa[j]>=len1) break;
plcp=min(plcp,he[j]);
}
int slcp=he[i+];
for(int j=i+;j<=len;j++){
if(sa[j]>=len1) break;
slcp=min(slcp,he[j]);
}
plcp=max(plcp,slcp);
if(plcp<len1-sa[i]){
if(plcp+<ans){
ans=plcp+;
pos=sa[i];
}
}
} if(pos==-) puts("Impossible");
else{
for(int i=;i<ans;i++)
printf("%c",s[i+pos]);
puts("");
}
}
int main()
{
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
scanf("%d",&n);
scanf("%s",s);
len=len1=strlen(s);
for(int i=;i<=n;i++){
s[len++]='#';
scanf("%s",s+len);
len=strlen(s);
}
m=;
get_suf();
printf("Case #%d: ",cas);
solve();
}
return ;
}
UVAL 7902 2016ECfinal F - Mr. Panda and Fantastic Beasts的更多相关文章
- 2016 ACM-ICPC China Finals #F Mr. Panda and Fantastic Beasts
题目链接$\newcommand{\LCP}{\mathrm{LCP}}\newcommand{\suf}{\mathrm{suf}}$ 题意 给定 $n$ 个字符串 $s_1, s_2, \dots ...
- 2016EC Final F.Mr. Panda and Fantastic Beasts
题目大意 \(T(1\leq T\leq42)\)组数据,给定\(n(2\leq n\leq 50000)\)个字符串\(S_{i}(n\leq\sum_{i=1}^{n}S_{i}\leq 2500 ...
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr. Panda and Fantastic Beasts
地址:http://codeforces.com/gym/101194 题目:略 思路: 这题做法挺多的,可以sam也可以后缀数组,我用sam做的. 1.我自己yy的思路(瞎bb的) 把第一个串建立s ...
- Gym 101194F Mr. Panda and Fantastic Beasts
#include<bits/stdc++.h> using namespace std; #define ms(arr,a) memset(arr,a,sizeof arr) #defin ...
- hdu6007 Mr. Panda and Crystal 最短路+完全背包
/** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...
- H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)
Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday. It is k ...
- Gym101194J Mr.Panda and TubeMaster 二分图、费用流
传送门 看到这张图,是一个网格图,而且有回路限制,不难想到黑白染色. 一般来说我们对一张图黑白染色之后都是黑色点向白色点连边,但是这道题往这边想似乎就想不出建图方法了,因为"一个格子强制流满 ...
- (CCPC-Final 2018)K - Mr. Panda and Kakin
题意:x是\([1e5,1e9]\)的随机数,p是小于x的最大素数,q是大于等于x的最小素数,\(n=pq\),\(c=f^{2^{30}+3}\mod{n}\),给n和c求f 题解:rsa解密,首先 ...
随机推荐
- 局域网传输-LED灯搭建局域网:数据传输可达每秒3Gb
一 : LED灯搭建局域网:数据传输可达每秒3Gb 我们之前介绍了利用可见光通讯技术,通过LED灯光实现精准室内定位的例子.实际上,这种灯泡和技术的用途不止于此,比如,它还能进行无线网络传输. 最近, ...
- 搭建gitpage博客
http://blog.csdn.net/jzooo/article/details/46781805
- Shell重新学习(忘光了)
成功和失败都放同一个文件 调试shell
- 第24次Scrum会议(11/12)【欢迎来怼】
一.小组信息 队名:欢迎来怼 小组成员 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文 小组照片 二.开会信息 时间:2017/11/12 17:05~17:32,总计27min. 地 ...
- Teamwork#3,Week5,Scrum Meeting 11.20
到目前为止,第一轮迭代已经基本完成.由于时间问题,多店比较的高级功能要放到第二轮迭代实现. 大部分任务已经完成,在alpha版本发布之前我们剩余需要解决的问题有两个: 服务器.校园网服务器不能满足我们 ...
- NEWBEE软件团队 人员分配情况及分数获得方式
人员分配: PM:李桐 王骜 dev:王骜 刘垚鹏 安康 林旭鹏 黄新越 test:黄伟龙 李桐 马佐霖 黄新越 注:黄新越为女生,不方便平时的交流,所以任务分配较为灵活,特分在两个组里. 评分 ...
- PAT 甲级 1010 Radix
https://pintia.cn/problem-sets/994805342720868352/problems/994805507225665536 Given a pair of positi ...
- PHP时间格式化参数表笔记
date_create_from_format() 函数返回一个根据指定格式进行格式化的新的 DateTime 对象.通常需要配合date_format()函数使用 语法: date_create_f ...
- [转帖]UsingDiskspdforSQLServer --- 改天做下练习 官方文档.
Using DiskSpd in SQL Server environments Writer: Robert Beene Contributors: Jose Barreto, Ramu Konid ...
- js 时间处理函数 (判断今天是否在一段时间内)
var curTime = new Date(); //2把字符串格式转换为日期类 var startTime = new Date(Date.parse("2018-3-28 16:44& ...