CodeForces 798B Mike and strings

CodeForces - 798B:Mike and strings CodeForces - 798B: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,... 阅读详情

题目链接:http://codeforces.com/contest/798/problem/B
题意:给你n个字符串,有一种操作叫做左移,左移一次就把第一个字符加到这个字符串的末尾,问你最少的操作数使得,这个n个字符串都相等,若不存在这种操作就输出-1
解析:由于n和字符串的长度都不大,那么直接暴力搞就好,枚举最终的字符串的答案,然后逐个匹配,然后更新ans记录最小值即可

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
string slove(string s,int k,int len)
{
    return s.substr(k,len-k)+s.substr(0,k);
}
int main(void)
{
    int n;
    scanf("%d",&n);
    string a[55];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int flag = 1,ans = inf;
    string t1 = a[0];
    int len = t1.length();
    for(int k=0;k<len;k++)
    {
        string tmp = slove(t1,k,len);
        //cout<<k<<" "<<tmp<<endl;
        int sum = 0;
        for(int i=0;i<n;i++)
        {
            int j=0;
            string tt;
            for(;j<len;j++)
            {
                tt = slove(a[i],j,len);
                if(tt==tmp)
                {
                    sum += j;
                    break;
                }
            }
            if(j==len)
            {
                flag = 0;
                break;
            }
        }
        if(!flag)
            break;
        ans = min(ans,sum);
    }
    if(!flag)
        puts("-1");
    else
        printf("%d\n",ans);
    return 0;
}
【unity游戏开发入门到精通——UGUI】UI控件 —— Image图像控件 阅读详情

相关推荐

保姆级教程:用海康威视老版存储服务器+IVMS-4200搭建本地监控录像(附软件获取与开机自启)

最近在帮朋友搭建一套小型监控系统时,遇到了一个颇具挑战性的问题:手头有几台海康威视网络摄像头,但官方已经下架了配套的存储服务器软件。经过一周的摸索和测试,终于找到了一套可靠的解决方案。本文将完整分享从软件获取到系统稳定运行的全过程,特别适合那些不想额外购买NVR设备,又需要本地存储监控录像的个人用户或小型企业IT管理员。

weixin_30553777的博客 532

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

制造业私有化LLM部署实战:从RAG到智能体,构建企业专属知识大脑

大型语言模型(LLM)作为人工智能的核心技术,通过在海量文本数据上进行预训练,具备了强大的语言理解和生成能力。其原理在于基于Transformer架构,通过自注意力机制捕捉长距离语义依赖。这一技术价值在于能将非结构化信息转化为可计算、可推理的知识,从而赋能企业实现知识的高效管理与应用。在制造业等强数据安全与知识密集型领域,私有化部署的LLM结合检索增强生成(RAG)和智能体(Agent)技术,能够深入业务流程,构建安全、专属的智能知识中枢。本文聚焦于如何利用Qwen、LangChain、向量数据库等技术栈,

weixin_42523711的博客 252

【CodeForces】【暴力】798 B Mike and strings

【题目】http://codeforces.com/problemset/problem/798/B 【题意】给出n个字符串,长度相同,有1种操作:将第一个字符放到最后,问最少需要操作多少次能使得这n个字符串变得相同? 【思路】    -&gt;遍历每个串,让第i个字符串当作目标串,看剩下的串变成这个串需要多少总代价                              -&gt;将其他的...

swqeaaa的博客 377

BIM模型轻量化避坑指南:Revit导出GLTF常见问题及解决方案

本文深入探讨了BIM模型轻量化过程中,从Revit导出GLTF格式时遇到的常见问题与解决方案。针对文件体积膨胀、材质丢失、属性信息缺失等核心痛点,提供了从数据预处理、Draco几何压缩、纹理优化到Web端性能调优的全流程实战指南,帮助工程师高效实现BIM模型在WebGL环境中的流畅展示与交互。

wdx012345的博客 173

Qt6.8.0(win64)安装教程

启动 Visual Studio 2022 Community,选择 “继续但无需代码” 运行,然后打开Option设置,Add一条版本配置,Location 选择 D:\Qt\6.8.0\msvc2022_64\bin\qmake,点击确定。我是win11系统,所以选择windows版,下载路径二选一即可。方案1:默认情况下,额外勾选图中两个组件(总共40多G)方案2:按图中自定义勾选组件(总共5.8G)选择Custom Installation。我选的方案2,总共5.81G。

D4G1TIAO的博客 9106

CodeForces - 798B Mike and strings (暴力+stl)

题目链接:http://codeforces.com/problemset/problem/798/B点击打开链接 B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input

xuejye的博客 2418

别再花钱买插件了!手把手教你实现UE5运行时动态导入FBX模型(附完整源码解析)

本文详细解析了UE5运行时动态导入FBX模型的全过程,从FBX SDK集成配置到核心解析流程,再到引擎资源转换和性能优化。通过多线程加载架构和内存优化技巧,开发者可以高效实现动态模型导入,避免购买昂贵插件。文章还提供了完整源码解析和高级功能扩展,帮助开发者深入理解UE5的底层资源管理机制。

weixin_27033895的博客 384

Mike and strings(思维)

题目链接: Mike and strings 大致题意: 对于某个字符串,可以将前面字符删除添加到末尾 问最少几步可以将这 n 个字符串都变成相同的,如果不行输出-1. 解题思路: 核心就是找n个字符最长的公共部分 这里用到string.find,如果找到会返回下标,没有找到,会返回npos AC代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; string s[100]; int main()

qq_49494204的博客 313

《R语言实战》第八章之回归分析图形

回归分析图形 回归分析分为简单回归与复杂回归 1 : 简单线性回归即:模型中只包含一个因变量和一个自变量,有时候也会包含多项式, 这个图形描述了身高与体重的线性关系,这也是一个多项式图形 2:当我们的预测变量(自变量)不止一个时,就属于多元线性回归,而且多元线性回归中也可以包含多项式以及交互项 (1)在进行多远回归分析之前可以先描述变量之间的相关关系 上图为一个散点图矩阵,描述了五个变量之间的相关关系,我们可以通过非主对角线的散点图来查看两个变量之间的关系。 多元线性回归简单地就是OLS回归,通过lm和

Strawberry_Ya的博客 1841

SAP采购申请审批策略配置简介

SAP采购申请审批策略配置简介 1、CT04创建特征

我小时候很黑的博客 8173

codeforces 798B Mike and strings

能暴力的水题就不要想别的了 #include #include #include #include using namespace std; const int N=55; string s[N],tmp[N][N]; int n,len; void gettmp(int t) { tmp[t][0]=s[t]; for(int i=1;i<len;++i) { tmp[t][i]=

359

《Python Web项目集锦》-专栏介绍和目录

本专栏专注于Python Web项目,涉及内容包含FastAPI、Django、Flask等,所有项目代码完整且可直接运行。不管是零基础还是有经验的开发,相信都能从本专栏获益。有任何问题欢迎私聊博主,专栏持续更新中...

数据知道的博客 5229

Codeforces798B Mike and strings

哈希大法好

ACoder 667

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

CodeForces - 798B Mike and strings

B. Mike and strings time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard 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 fi

海岛Blog 481

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Codeforces798B-Mike and strings

B. Mike and stringstime limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Mike has n strings s1, s2, …, sn each consisting of lowercase English le

algzjh的博客 1171

CodeForces - 798B Mike and strings

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 one mo

weixin_51996479的博客 306

小白题解 Codeforces 798B Mike and strings

Codeforces 798B Mike and strings 题解 (模拟题,暴力求解) 题目链接:点击打开链接 题目大意:给出一组长度相同的字符串,每次操作可以将一个字符串的首元素放到末尾,要使各字符串完全一致,需要多少次操作。 分析:以第一个字符串顺序为依照,依次枚举最终字符串以s[0][i]开头的情况,对每种情况去分别计算每个字符串需要的操作数并求和,最终再找到cnt[i]最小值即为答案。复杂度是n^4,可过。 下面是AC代码(用来好长时间debug)

Talk is cheap,give me the code! 700

codeforces 798B - Mike and strings

感觉自己好咸鱼呀……B题写了这么久,虽然可以算作1A(忽略一次少include一个头文件的CE)…… 思想很简单,每次选定一个字符串作为目标字符串,然后把其他所有字符串都当做测试字符串,计算出总共需要的步数,再在这些计算出的步数中找到最小的那个就是答案。 #include #include #include using namespace std; char str[53][105]; int

Dilthey's Blog 1127

Codeforces 798B Mike and strings

题意:           给出 N 个串,问最少能移动几次使 N 个串都相等。           移动的规则是,每次只能将一个串首的字符移到串尾。           N 最大 50,串长最大 50。 思路:           竟然是暴力题。 50^4 并不超时…… 代码: #include #include #include #include #include us

DT2131 832

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

Mike and strings CodeForces - 798B

Mike and strings CodeForces - 798B 菜的扣脚,哭唧唧哭叽叽可能是没怎么写过kmp的题??????自以为正确的思路和大佬说了一遍漏洞百出。最后还是扩大两倍,直接一个一个找最先出现的位置。然后加上去,一次没找到就输出-1(因为肯定找不到了)。 #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;i...

DeathYmz的博客 478

【codeforces 798B】Mike and strings

【题目链接】:http://codeforces.com/contest/798/problem/B 【题意】 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去了) 问你最少经过多少次操作可以使得所有字符串都相同; 【题解】 枚举最后每个字符串都变成了哪一个字符串; 然后每个字符串都模拟一下左移的过程;直...

AWCXV 175

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的博客 492

CodeForces - 798B Mike and strings

题目链接 给定n个字符串,一次操作将某一字符串的首字符移到末尾,问经过操作后都相等的最少移动次数。 每个字符串最大范围是移动n次,所以mp数组初始化为输入值的两倍,再利用find函数查找匹配的位置,下标相加求最小。 #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cmath&gt; #include&lt;algorit...

M_Lter的博客 216

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 hasnstringss1, s2, ..., sneach consist...

weixin_33941350的博客 93
上一篇: CodeForces 798A Mike and palindrome
下一篇: CodeForces 798C Mike and gcd problem
15zhazhahe
博客等级 码龄11年 49粉丝 360原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值