Codeforces #410(div2) B. Mike and strings (暴力枚举

RK3588嵌入式开发实战:U-Boot设备树文件修改全指南(含常见踩坑点) 本文为RK3588嵌入式开发者提供了一份详尽的U-Boot设备树文件修改实战指南。文章深入解析了设备树的核心架构,从基础硬件适配到时钟、电源管理等进阶配置,并重点总结了内存节点、串口输出、电源时序等常见踩坑点与解决方案,旨在帮助开发者高效、稳健地完成U-Boot移植与定制工作。 阅读详情

B. Mike and strings

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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?

Input

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.

Output

Print the minimal number of moves Mike needs in order to make all the strings equal or print  - 1 if there is no solution.

Examples
Input
4
xzzwo
zwoxz
zzwox
xzzwo
Output
5
Input
2
molzv
lzvmo
Output
2
Input
3
kc
kc
kc
Output
0
Input
3
aa
aa
ab
Output
-1
Note

In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into “zwoxz“.

暴力枚举所有情况QAQ

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int mod = 1e9+7;
const int N = 1010;
char q[100], a[100],w[100];
char str[N][N];
int n, len;
void f(char aa[],char b[], int x)
{
    for(int i = 0;i < len; i++) {
        aa[i] = b[(i+x)%len];
    }
//  aa[len] = '\0';
}
int main()
{
    scanf("%d",&n);
    getchar();
    scanf("%s",a);
    for(int i = 1;i < n; i++) scanf("%s",str[i]);
    len = strlen(a);
    int ans = inf;
    for(int i = 0;i <= len-1; i++) {
        int tmp = i;
        f(q,a,i);
        int go = 0;
        for(int j = 1; j < n; j++) {
            int low = inf;
            for(int k = 0;k <= len-1; k++) {
                f(w,str[j],k);
                if(strcmp(q,w)==0) {
                    tmp += k;
                    go++;
                    break;
                }
            }
        }
        if(go == n-1) ans = min(ans,tmp);
    }
    if(ans == inf) puts("-1");
    else    printf("%d\n",ans);
return 0;
}


















汉书HE8,好用的汇编代码编写工具 汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大 立即下载

相关推荐

国产麒麟系统下用Rider开发C#桌面应用:从环境配置到Avalonia UI实战

本文详细介绍了在国产麒麟系统上使用JetBrains Rider开发C#桌面应用的完整流程,重点讲解了Avalonia UI框架的实战应用。从环境配置、Rider安装到Avalonia项目创建和UI开发技巧,全面覆盖了在非Windows环境下进行C#开发的关键步骤和优化建议,助力开发者高效构建跨平台桌面应用。

weixin_27791839的博客 392

CodeForces - 798B Mike and strings 【思维】

Description(下方有汉语题意) Mike hasnstringss1, s2, ..., sneach consisting of lowercase English letters. In one move he can choose a stringsi, erase the first character and append it to the end of the ...

MengHao的博客 634

BUCK电路三种工作模式全解析:CCM、BCM、DCM到底怎么选?

本文深入解析BUCK电路的CCM、DCM和BCM三种工作模式,通过对比其电流波形、效率、纹波及环路特性,提供基于计算公式的量化判断方法。文章结合电池供电、高精度模拟等具体应用场景,给出明确的模式选型策略与实战设计指南,帮助工程师根据核心需求做出最优决策。

ee345的博客 505

B. Mike and strings string Find 函数运用

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 ...

loooooog的博客 428

用Matlab搞定Delta并联机器人运动学:从建模到正逆解完整流程(附代码)

本文详细介绍了如何使用Matlab实现Delta并联机器人的运动学分析,包括几何建模、正逆解求解及可视化验证。通过符号计算和数值迭代法,解决非线性方程组问题,并提供完整代码示例,帮助读者快速掌握Delta机器人的运动学计算与应用。

weixin_30955617的博客 185

给STM32供电,别只接VDD和GND!VBAT、VDDA这些引脚不接会怎样?

本文深入解析STM32电源设计中VBAT与VDDA引脚的关键作用,揭示仅连接VDD和GND可能导致的ADC精度下降、RTC功能异常等问题。通过实测数据对比不同连接方案,提供包括滤波电路设计、PCB布局布线和双电源自动切换在内的实用解决方案,帮助开发者优化系统稳定性与性能。

weixin_30521161的博客 639

Mike and strings //find()函数的使用

A - Mike and strings 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 on

qq_51662567的博客 293

神州路由器DHCPv6配置

神州路由器DHCPv6配置.。

weixin_41687096的博客 467

CodeForces - 578B "Or" Game (暴力)

题目链接:点击打开链接题意:给你n个数,你一共能对这个n个数操作k次,操作为对某个数乘x。求两两或运算的最大值。题解:对于这个问题,最开始并没有任何思路,就想着瞎暴力试试,然后我就遇到了,如何分配那个数乘x的问题。后来我发现,对多个数字乘x是没有意义的。因为若ai 比 其他 aj 的二进制都多一位,那么无论aj怎么|或运算,都不会影响到xi的最高位。所以让某个值最大化,才是我们应该做的。也就是针对...

PK__PK的博客 324

【2026最新版】python点云处理算法汇总(长期更新版)

python点云处理算法整理。博客长期更新,最近一次更新时间为:2026年10月4日。

点云侠的博客 42万+

【运动规划算法项目实战】Artificial Potential Field算法(附ROS C++代码)

在机器人行业中,路径规划是一个关键的任务,它涉及到如何让机器人在复杂的环境中安全而高效地移动。人工势场算法(Artificial Potential Field Algorithm)是一种常用的路径规划方法,它借鉴了物理学中的势能概念,通过模拟力的作用来引导机器人的移动。本文将详细介绍人工势场算法的原理、在路径规划中的应用、算法优缺点以及代码实现。人工势场算法基于两种势场:斥力场和引力场。斥力场使机器人远离障碍物,而引力场将机器人吸引到目标位置。

xiewf的博客 1万+

字符串的小处理

B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each

Accepted ALL lve 621

【推荐100个unity插件】Animator 的替代品?—— Animancer Pro插件的使用介绍

Animancer与Unity Animator对比及使用指南 摘要: 本文对比了Animancer与Unity官方Animator的核心差异,分析了Animancer的优势特点。Animancer采用代码驱动模式,相比Animator的状态机系统更灵活高效,支持实时调试、动态混合和深度逻辑集成。文章详细介绍了Animancer的快速使用方法,包括动画播放、切换和触发机制,并区分了免费版与专业版的功能差异。适合需要高效动画开发、复杂交互逻辑的中小项目,为开发者提供了一种现代化的动画解决方案。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2448

【解题报告】Codeforces Round #410 (Div. 2)

简略的解题报告。

TRiddle的博客 1146

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)

传送门 Description Mike hasnstringss1, s2, ..., sneach consisting of lowercase English letters. In one move he can choose a stringsi, erase the first character and append it to the end of the st...

weixin_30752699的博客 65

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

CF798B:Mike and strings(Hash)

B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each

junior19的博客 579

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

CodeForces - 798B Mike and strings —— 暴力

B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each

Lngxling的博客 491

B. Mike and strings

B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each

Nice_punch的博客 1138

CF#798 B. Mike and strings(思维)

B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each

xiaotuji的博客 1109

Codeforces Round #704 (Div. 2) B. Card Deck(暴力)

给出大小为n 的排列,每次操作从后面开始取,取任意大小为 k 的长度组成一种新的排列,问最后这种排列字典序最大是多少 其实很容易发现最优的排列应该类似于 也就是说从后面开始找这几个点,但是不能够保证 n 之后我们要找的点是 n-1 ,因为 n-1 可能已经与 n 组成排列,所以利用一个数组来找到下一个需要找的点是什么即可 const int N=5e5+5; int n,m; int i,j,k; int a[N]; bool vis[N...

C_Dreamy的博客 676

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 input output standard output Mike has n strings s1, s2, ..., sn each

WhaleFall 764

AAOS电源管理核心:onApPowerStateChange回调与下电状态机实战解析

车载系统的电源管理与普通单机不同,它需要响应整车分阶段下电指令,在有限的窗口内完成数据保存、服务关闭与状态切换。Android 13 AAOS架构中,CarPowerManagementService作为统一调度中枢,通过onApPowerStateChange回调接收来自Vehicle HAL的电源事件,驱动ApPowerStateManager状态机迁移,并基于CarPowerPolicy向各组件分发策略。理解这条链路,是排查车机睡死、关机白屏、数据丢失等问题的关键。本文从状态机原理、策略分发机制入手,

weixin_33857679的博客 380

数学题 暴力字符串 Codeforces div2 E. Pretty Song

Codeforces Round #289 (Div. 2, ACM ICPC Rules) 求一个字符串的所有字串的权值和,每个字串的权值为元音字母的个数比上字串的长度 将字串转化为01串,那么区间[l,r]的字串的权值为(s[r]-s[l-1])/(r-l+1),枚举长度k,则所有字串的权值和为 Sigma(1/k *(s[k]-[s0] + s[k+1]-s[1]+...s

ACM_10000h的专栏 816

字符串———find()函数

假设我们有字符串a和b,那么a.find(b)是指在a这个字符串中查找b并返回b开头字母的位置,没查到就是-1 例题: 链接 这个题有两种解法,一种是暴力嘛,因为字符串的数量也不多,还有一种呢则是利用到find函数 ①首先将该串复制一遍 ②遍历查找原本母串能不能找到 ③找到了的话需要移动的值就是find返回的值 ④没找到就是-1 结束over~ 下面是针对样例2的过程 2 molzv lzvmo ...

RIPKEY的博客 5988

string中的find函数和string::npos的使用

转载至http://www.cnblogs.com/web100/archive/2012/12/02/cpp-string-find-npos.html 查找字符串a是否包含子串b, 不是用strA.find(strB) > 0而是strA.find(strB) != string:npos string::size_type pos = strA.find(strB); if(po

codeswarrior的博客 4492

A - Mike and strings(str.find(“字符串“)==string::npos)

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 transfo

qq_51690274的博客 276
上一篇: 51Nod 1042 数字0-9的数量 (数位DP
下一篇: 51Nod 1596 搬货物 (数学
Yishui_Blog
博客等级 码龄10年 96粉丝 524原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值