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行) ...
随机推荐
- Kafka VS Flume
(1)kafka和flume都是日志系统.kafka是分布式消息中间件,自带存储,提供push和pull存取数据功能.flume分为agent(数据采集器),collector(数据简单处理和写入) ...
- Android SDK Manager 无法更新问题(转载)
先看看如何加快更新速度,再说如何更新. 首先更新host文件,如图,打开目录 C:\Windows\System32\drivers\etc,在目录下有hosts文件 打开方式选用“记事本”打开 将一 ...
- Android开发之Thread类分析 (转载)
转自:http://blog.csdn.net/llping2011/article/details/9706599 在我们Linux系统中创建线程函数为:pthread_create(),在Andr ...
- PCB 围绕CAM自动化,打造PCB规则引擎
AutoCAM自动化平台,前端管理订单,而后端执行任务,前端UIl界面有板厚,铜厚,板材,表面处理,层数等信息,而这些信息并不是后端最终所需要的信息后.拿钻孔补偿来说,后端需要的是钻孔补偿值,但前端并 ...
- 各地图API坐标系统比较
各地图API坐标系统比较 简单记录一下各家坐标系 WGS84坐标系:即地球坐标系,国际上通用的坐标系.设备一般包含GPS芯片或者北斗芯片获取的经纬度为WGS84地理坐标系,谷歌地图采用的是WGS84地 ...
- ACM_汉诺塔问题(递推dp)
Problem Description: 最近小G迷上了汉诺塔,他发现n个盘子的汉诺塔问题的最少移动次数是2^n-1,即在移动过程中会产生2^n个系列.由于发生错移产生的系列就增加了,这种错误是放错了 ...
- asp.net MVC 给Controler传一个JSon集合,后台通过List<Model>接收
需求情景 View层经常需要通过Ajax像后台发送一个json对象的集合,但是在后台通过List<Model>无法接收,最后只能通过妥协的方式,在后台获取一个json的字符串,然后通过Js ...
- SAS学习笔记之《SAS编程与数据挖掘商业案例》(2)数据获取与数据集操作
SAS学习笔记之<SAS编程与数据挖掘商业案例>(2)数据获取与数据集操作 1. SET/SET效率高,建立的主表和建表索引的查询表一般不排序, 2. BY语句,DATA步中,BY语句规定 ...
- ZUK Z2 Pro(Z2121) 免解锁BL 免rec Magisk Xposed ROOT 救砖 ZUI 4.0.247
>>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...
- Android studio USB连接失败
Android studio USB连接失败,可能是因为adb的端口被占了,此时在其自带的cmd中输入netstat -aon|findstr "5037",并且启动任务管理器关掉 ...