CF410div2 B. Mike and strings
/*
CF410div2 B. Mike and strings
http://codeforces.com/contest/798/problem/B
字符串 暴力
题意:给你n个串,每次操作可以将某个串的第一个字符放到最后去,
问最少的次数,使得所有字符串都相同
思路:先将所有字符串复制成二倍,然后暴力枚举要变成的串
注意数组都要开二倍。。
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <set>
//#define test
using namespace std;
const int Nmax=;//空间记得要开两倍
char s[Nmax][Nmax];
char tmp[Nmax];
int ans[Nmax][Nmax];
int n,len=;
int check(int a,int b)
{
for(int i=b;i<=b+len-;i++)
{
if(tmp[i-b+]!=s[a][i])
return ;
}
return ;
}
int main()
{
#ifdef test
#endif
//freopen("2.in","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%s",s[i]+);
//printf("%s\n",s[i]+1);
len=max(len,(int)strlen(s[i]+));
for(int j=len+;j<=len<<;j++)
s[i][j]=s[i][j-len];
}
for(int i=;i<=len;i++)//枚举匹配头
{
int k=i;
for(int j=;j<=len;j++)
tmp[j]=s[][k++];
for(int j=;j<=n;j++)
{
int flag=;
for(int t=;t<=len;t++)
{
if(check(j,t))
{
ans[j][i]=t-;
//printf("ans[%d][%d]=%d\n",j,i,ans[j][i]);
flag=;
break;
}
}
if(flag)
{
printf("-1\n");
return ;
}
}
}
for(int i=;i<=len;i++)
ans[][i]=i-;
int res=1e9,book=;
for(int t=;t<=len;t++)
{
book=;
for(int i=;i<=n;i++)
book+=ans[i][t];
//printf("book[%d]:%d\n",t,book);
res=min(res,book);
}
printf("%d\n",res);
return ;
}
CF410div2 B. Mike and strings的更多相关文章
- Mike and strings 798B
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #410 (Div. 2) B. Mike and strings
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF410div2 A. Mike and palindrome
/* CF410div2 A. Mike and palindrome http://codeforces.com/contest/798/problem/A 水题 */ #include <c ...
- CF410div2 D. Mike and distribution
/* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...
- #410(div2)B. Mike and strings
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
传送门 Description Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In ...
- Mike and strings
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can ...
- Mike and strings CodeForces - 798B (简洁写法)
题目链接 时间复杂度 O(n*n*|s| ) 纯暴力,通过string.substr()函数来构造每一个字符串平移后的字符串. #include <iostream> #include & ...
- Mike and strings CodeForces - 798B (又水又坑)
题目链接 题意:英语很简单,自己取读吧. 思路: 既然n和i字符串的长度都很小,最大才50,那么就是只要能出答案就任意暴力瞎搞. 本人本着暴力瞎搞的初衷,写了又臭又长的200多行(代码框架占了50行) ...
随机推荐
- scrapy xpath中提取多个class值
xpath中没有提供对class的原生查找方法.但是 stackoverflow 看到了一个很有才的回答: This selector should work but will be more eff ...
- Django day25 序列化组件(*****)
序列化:将变量从内存中存储或传输的过程称之为序列化 1.序列化组件是干什么用的? 对应着表,写序列化的类 2.如何使用序列化组件 Serializer 1) 重命名:用source:xx = seri ...
- Git 标记操作
.推送标签: git push origin 标签名 .删除本地标签: git tag -d 标签名 .删除远程标签: git push origin :refs/tags/标签名 例:git pus ...
- Jsp入门小常识
因为选修了一门信息系统的课,选择了用jsp做了一个系统.在这期间自学了jsp的一点皮毛,特与大家分享: script标签:用于向jsp中嵌入java代码块,<% // embed java c ...
- Android webview js 调用java方法报错"Uncaught TypeError: Object [object Object] has no method xx
webview开发,在Android4.4下js调用java方法报错"Uncaught TypeError: Object [object Object] has no method,同样的 ...
- Mac使用bootcamp安装win8.1出现网卡驱动没有安装问题
问题:没有网络连接 原因:在bootcamp烧的u盘里面其实附带了驱动,只是没有自动安装 解决:D:\BootCamp\Drivers\Broadcom\BroadcomWirelessWin8x64 ...
- C#中的分层开发
一般来说,分层主要分三层即:UI(User Interface) 界面显示层,BLL(Business Logic Layer)业务逻辑层,以及DAL(Data Access Layer)数据访问层. ...
- 用CSS样式写选择框右侧小三角
直接上代码! <!DOCTYPE html><html lang="en"><head> <title>小三角</title& ...
- 超经典~超全的jQuery插件大全
海量的jQuery插件帖,很经典,不知道什么时候开始流传,很早以前就收藏过,为了工作方便还是发了一份放在日志里面. 其中有些已经无法访问,或许是文件移除,或许是被封锁.大家分享的东西,没什么特别的可说 ...
- 2015.12.20-2015.12.25 大论文迭代 A
进一步充实大论文内容.结构,完善一遍大论文 12.20周天,完成论文第五章总结部分,和第一章的修改 12.21周一,完成论文第二章的修改充实 12.22周二,完成论文第三章的修改充实 12.23周三, ...