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行) ...
随机推荐
- Request returned failure status 401
Request returned failure status 401.Invalid OpenStack Identity credentials.
- 【Hibernate总结系列】使用举例
本节讲述如何使用Hibernate实现记录的增.删.改和查功能. 1 查询 在Hibernate中使用查询时,一般使用Hql查询语句. HQL(Hibernate Query Language),即H ...
- P2533 [AHOI2012]信号塔
传送门 据说是一个叫做随机增量法的东西 枚举\(i\),如果不在圆中将它设为圆心 枚举\(j\),如果不在圆中将\((i,j)\)成为新的圆的直径 枚举\(k\),如果不在圆中让\(i,j,k\)组成 ...
- Akka源码分析-local-DeathWatch
生命周期监控,也就是死亡监控,是akka编程中常用的机制.比如我们有了某个actor的ActorRef之后,希望在该actor死亡之后收到响应的消息,此时我们就可以使用watch函数达到这一目的. c ...
- Python基础数据类型(五) dict字典
字典dict{} 字典数字自动排序 enumerate 枚举 for i,k in enumerate(dic,1) #第二个参数默认不写就是0 ---枚举 print(i,k) dict,以{}来表 ...
- C#中Random
说明:C#中的随机数是一个伪随机数,随机数字从一组有限的数字选择以相同的概率,所选的数字不是完全随机的,因为使用数学算法来选择它们.在大多数Windows系统中,Random的15毫秒内创建的对象很可 ...
- printf的字符型
参 数 说 明 %s 按实际宽度输出一个字符串 %ms m指定宽度(不足时左补空格,大于时按实际宽度输出) %-ms 左对齐,不足时右补空格 %m.ns 输出占m个字符位置,其中字符数最多n个,左 ...
- ACM_Jack拆炸弹(深搜)
Jack拆炸弹 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在一个由n*n个格子组成的监狱里被恐怖份子安置了一个定时炸弹.其中 ...
- dedecms:解析Robots.txt 协议标准
Robots.txt 是存放在站点根目录下的一个纯文本文件.虽然它的设置很简单,但是作用却很强大.它可以指定搜索引擎蜘蛛只抓取指定的内容,或者是禁止搜索引擎蜘蛛抓取网站的部分或全部内容. 下面我们就来 ...
- Unity 引擎UGUI之自定义树形菜单(TreeView)
先上几张效果图: 如果你需要的也是这种效果,那你就来对地方了! 目前,我们这个树形菜单展现出来的功能如下: 1.可以动态配置数据源: 2.点击每个元素的上下文菜单按钮(也就是图中的三 ...