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

android 3D画廊 总结,供自己以后参考而已、 立即下载

题目链接: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
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".


数据量很小可以直接进行暴力判断

至于判断负一的情况 可以根据次数是否超过了对一个字符串的所有循环次数即可

#include <bits/stdc++.h>
using namespace std;
int main()  
{  
	string s[55];
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> s[i];
	}
	int ans=n*s[0].length();
	int flag=0;
	for(int i=0;i<=s[0].length();i++)
	{
		int cnt=i;
		if(i!=0)
		{	
			char c=s[0][0];
			s[0].erase(s[0].begin());
			s[0]+=c;
		}
		for(int j=1;j<n;j++)
		{
			string mid=s[j];
			int ccnt=0;
			while(mid!=s[0]&&ccnt<=mid.length())
			{
				ccnt++;
				char c=mid[0];
				mid.erase(mid.begin());
				mid+=c;
			}
			if(ccnt>mid.length())
				flag=1;
			cnt+=ccnt;
		}
		ans=min(ans,cnt);
	}
	if(flag)
		cout << "-1" << endl;
	else 
	cout << ans << endl;
}  	















zhidd#ZXBlog#Codeforces - 1107B. Digital root & 1107C. Brutality Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B. 立即下载

相关推荐

无感无刷电机控制进阶:反电动势过零检测的5种实现方案对比

本文深入探讨无感无刷电机控制中反电动势过零检测的5种实现方案,包括电阻分压虚拟中性点法、专用BEMF检测IC方案、基于ADC采样的数字锁相环、无传感器观测器技术及混合方案创新实践。通过对比分析各方案的优劣及适用场景,为电机控制工程师提供实用的技术选型指南,助力提升系统性能与成本效益。

weixin_28691741的博客 869

CodeForces 1084B

这题题意是给你n个装有ai酒的桶,让你从中匀出s公升的酒并且让所有桶中酒尽量在一个数量上,输出桶最少酒的数量。   这题读错了题意卡了好久。   #include&lt;bits/stdc++.h&gt; #define ll long long using namespace std; ll n,s,sum; ll a[1010]; int main(){ cin&gt;&g...

Zhengggggg的博客 789

ESP32+LED12864液晶屏实战:手把手教你显示中文与自定义图标(附完整代码)

本文详细介绍了如何使用ESP32单片机驱动带字库的LED12864液晶屏,实现中文显示与自定义图标。从硬件选型、接线方案到驱动编写、字库解析,提供了完整的实战代码与优化技巧,并最终构建了一个智能家居控制面板的完整示例项目。

weixin_29212867的博客 154

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

yolo自动化项目实例解析(九) 导航

比如我们经常使用的导航,说白了就是寻找两点之间最近的路径,也就是所谓的寻路,我们需要想办法让程序知道他要去哪里,路径包含(起点、轨迹、路径)

默子昂 2005

锂电池寿命预测 | Python实现基于LSTM长短期记忆神经网络的锂电池寿命预测

锂电池寿命预测 | Python实现基于LSTM长短期记忆神经网络的锂电池寿命预测

算法如诗的博客 1908

【CodeFores 798B】 Mike and strings(模拟+string)

 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

FSMM_blog 681

Dify 第 13 篇 Dify 工作流 详解

工作流通过将复杂任务分解为节点降低复杂度,提升LLM应用的性能和稳定性。Dify工作流分为两类:Chatflow面向对话场景(如客服),支持多轮对话;Workflow面向批处理场景(如翻译),提供逻辑节点实现自动化。核心概念包括节点、变量(系统/会话/环境变量)及应用类型差异:Chatflow支持中间输出和对话历史,Workflow仅支持结束节点输出。系统变量以"sys"开头,用于全局数据传递,不同应用类型变量不同,如Chatflow的sys.query存储用户输入,Workflow的s

甘蓝的专栏 3271

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

Unity之如何实现TTS文本转语音(真人发音)

微软Azure TTS 文本转语音 服务 将文本转换为逼真的语音的语音服务功能 支持个各国语言,各种中文各种方言,支持不同音色男音女音 支持离线和在线版本

TxNet 5491

面试问题总结——关于YOLO系列(三)

接着上篇的的YOLO系列面试问题总结,加油,冲! 三.YOLOv3 1.YOLOv3主干网络BackBone——Darknet-53网络结构(因为有53个卷积层) (原论文中Darknet53的尺寸是在图片分类训练集上训练的,所以输入的图像尺寸是256x256,而在YOLOv3中输入尺寸是416×416)   ①上图中,Top-1 Accuracy和Top-5 Accuracy是指什么呢?区别在哪呢?   我们知道ImageNet有大概1000个分类,而模型预测某张图片时,会给出1000个按概率从高.

boss-dog 1万+

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

啊啊啊啊……颓了好久了……然而……果然还是只能做一做div2的ab,b做起来都困难啊orz○| ̄|_ 题目链接:http://codeforces.com/contest/798/problem/B 唉,这个题写了好久啊,实现起来巨麻烦,看了看大佬的代码发现,同样都是暴力的想法,大佬的代码要简洁的多,果然还是对STL不熟悉么还是其他什么的。 暴力,分别以每个字符串为基准,计算其他几个字符串移...

weixin_30764137的博客 64

【大语言模型 21】语言模型训练目标:MLM vs CLM vs GLM对比分析

本文深入对比分析三种主流语言模型训练目标:掩码语言模型(MLM)、因果语言模型(CLM)和双空白填充(GLM)。通过数学推导、代码实现和实验对比,揭示不同训练目标的工作机制、适用场景和性能差异,为选择合适的预训练策略提供科学指导。

熵数实验室 1183

Codeforces Round #410 (Div. 2)-B. Mike and strings-string的使用和取模

给定一些字符串,每次把对头的放在最后,问需要多少操作才能让他们相等 开始以为是贪心,或者感觉无处可贪,应该是暴力。 题解中大概有三个版本。 第一个最简单的,因为运用了stl中的find函数,所以比较简单了 因为要涉及循环比较,所以每个串都加了一倍的长度。 然后直接find就好。 两个代码的整体实现方法都一样,但是用的手段不一样。 一个是用的stl(棒棒哒) 另一个是用的取模的思想和一

天与云与山与水 438

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Mike and strings

Mike and strings string:npos是个特殊值,说明查找没有匹配 str.find(a)==string::npos; 意思是,查找字符串str中是否含有字串a str.find(a)返回的是字符串的第一个字符的下标 #include<bits/stdc++.h> using namespace std; typedef long long ll; string a[100]; int main() { int n; cin>>n; for

m0_45920074的博客 190

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

codeforces B. Mike and strings 暴力+字符串

题意:给定n个字符串,可以进行一个这样的操作,将第一个字符移动到最后一个字符的后面,可以形成一个新的字符串,如:name进行一次操作,得到amen。求出最小移动次数,使得n个串相等,如果做不到,输出-1,否则输出次数。 思路:每次选定一个串为目标串,其他的串为测试串,将测试串移动,使得所有串相等,求得最小。如果移动了长度个单位,说明不管进行多少次移动,都无法是的所有串相等,这时是-1 #inc

chen_minghui的博客 599

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

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

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

京东

京东售后服务太差

kidld的专栏 362

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

codeforces 798B - Mike and strings

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

Dilthey's Blog 1127

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

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

weixin_33857679的博客 380

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
上一篇: CodeForces - 540B School Marks (构造)
下一篇: HDU - 1711 Number Sequence (KMP)
xuejye
博客等级 码龄9年 35粉丝 297原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值