#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)…… 思想很简单,每次选定一个字符串作为目标字符串,然后把其他所有字符串都当做测试字符串,计算出总共需要 ...
随机推荐
- Zookeeper启动Permission denied
Zookeeper 查询状态,出现如下问题: JMX enabled by default Using config: /usr/zookeeper/zookeeper-/bin/../conf/zo ...
- vim编辑器常规配置
为了很舒服的编写程序,请把vim配置好 # apt install vim 安装vim编辑器 #sudo vim /etc/vim/vimrc ///必须加上权限sudo 在这个文件中,会有 ...
- Mysql——JDBC编程 简单的例子
第一类连接Mysql方法见下图: 第二类连接Mysql方法:(跟第一类差不多,并提供查询操作) 首先在Mysql中建立testjdbc数据库,在该数据库下面建立Student表: 参考代码: CREA ...
- P4240 毒瘤之神的考验
题目 P4240 毒瘤之神的考验 神仙题\(emmm\) 前置 首先有一个很神奇的性质: \(\varphi(ij)=\dfrac{\varphi(i)\varphi(j)gcd(i,j)}{\var ...
- thinkphp 的 Action 控制器中的系统常量总结
THINK_PATH // ThinkPHP系统目录 APP_PATH // 当前项目目录 APP_NAME // 当前项目名称 CONTROLLER_NAME // 当前控制器名称 MODULE_N ...
- ios 微信发送位置
@interface GroupReportViewController () <BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCode ...
- spring boot拦截器
实现自定义拦截器只需要3步: 1.创建我们自己的拦截器类并实现 HandlerInterceptor 接口. 2.创建一个Java类继承WebMvcConfigurerAdapter,并重写 addI ...
- Spark官网
Components Spark applications run as independent sets of processes on a cluster, coordinated by the ...
- C++(五)— 控制保留小数位数
1.C++中输出指定保留的小数位数. 这里还要注意,每次输出只要设置一次就行了,因为这两个的作用范围是后续对象,而不是仅对后一个对象起作用. #include<iostream> #inc ...
- 造成segmentation fault的可能原因分析
一 造成segment fault,产生core dump的可能原因 1.内存访问越界 a) 由于使用错误的下标,导致数组访问越界 b) 搜索字符串时,依靠字符串结束符来判断字符串是否结束,但是字符串 ...