#410(div2)B. Mike and strings
2 seconds
256 megabytes
standard input
standard output
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal?
The first line contains integer n (1 ≤ n ≤ 50) — the number of strings.
This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50.
Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution.
#include<bits/stdc++.h>
#define INF 1000000
using namespace std;
typedef long long ll;
string s[];
ll n;
int main(){
scanf("%lld",&n);
for(int i=;i<n;i++){
cin>>s[i];
}
int ans=INF;
for(int i=;i<n;i++){
int cnt=;
for(int j=;j<n;j++){
string temp=s[j]+s[j];
if(temp.find(s[i])==-){
cout<<-<<endl;
return ;
}//不需判断是否相等,因为相等时,步数为0
cnt+=temp.find(s[i]);
}
ans=min(ans,cnt);
}
cout<<ans<<endl;
return ;
}
#410(div2)B. Mike and strings的更多相关文章
- 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 ...
- Mike and strings 798B
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF410div2 B. Mike and strings
/* CF410div2 B. Mike and strings http://codeforces.com/contest/798/problem/B 字符串 暴力 题意:给你n个串,每次操作可以将 ...
- 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行) ...
- Codeforces#543 div2 B. Mike and Children(暴力?)
题目链接:http://codeforces.com/problemset/problem/1121/B 题意 给n个数 最多的对数 其中每一对(i,j)的ai+aj都相等(不知道怎么解释.... 判 ...
- codeforces 798B - Mike and strings
感觉自己好咸鱼呀……B题写了这么久,虽然可以算作1A(忽略一次少include一个头文件的CE)…… 思想很简单,每次选定一个字符串作为目标字符串,然后把其他所有字符串都当做测试字符串,计算出总共需要 ...
随机推荐
- 更改node版本
npm install -g n n stable 或 n v4.5.0
- Android系统Recovery模式的工作原理【转】
本文转载自:http://blog.csdn.net/mu0206mu/article/details/7464987 在使用update.zip包升级时怎样从主系统(main system)重启进 ...
- Thinkphp跨模块调用视图文件
当需要跨模块调用视图文件时,需要使用被包含文件的完整路径,如: <include file="./App/Home/View/Store/header.html"/> ...
- type为number的input标签输入小数的方法
纠结了一段时间都没找出方法,最后灵光一现想出这个方法,没想到测试下果然成功了! 看目前网上几乎很难找到相对应的解决方法,所以这里分享出来,如果有更佳方法欢迎提出. 方法如下: <input ty ...
- L105
A pill could soon radio signals from inside your gut to help doctors diagnose diseases from ulcers t ...
- BEC listen and translation exercise 46
录音文件 https://pan.baidu.com/s/1qYYZGWO The process of learning and exploring a subject can lead to a ...
- web前端绘制0.5像素的几种方法
最近完成了公司安排的移动web触屏开发,期间涉及到在移动设备上显示线条,最开始采用PC常用的css board属性来显示1个像素的线条,但是发现在移动设备上并不美观,参考淘宝.京东的触屏发现它们均是采 ...
- codeforces 598C C. Nearest vectors(极角排序)
题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- BZOJ5461: [PKUWC2018]Minimax
BZOJ5461: [PKUWC2018]Minimax https://lydsy.com/JudgeOnline/problem.php?id=5461 分析: 写出\(dp\)式子:$ f[x] ...
- cmdb1--介绍
背景:现在运维管理服务器多数使用Excel表来维护,而且是多人来维护,造成信息不统一,所以要将信息入库,并方便后续的批量操作 1.cmdb主要分3块: a.采集信息程序 b.API提供接口 c.后台管 ...