Codeforces Round #394 (Div. 2) C. Dasha and Password

龙头复盘神器/复盘于导出工具最新版5.6 龙头复盘神器,复盘于导出工具 阅读详情

C. Dasha and Password
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements:

  • There is at least one digit in the string,
  • There is at least one lowercase (small) letter of the Latin alphabet in the string,
  • There is at least one of three listed symbols in the string: '#', '*', '&'.

Considering that these are programming classes it is not easy to write the password.

For each character of the password we have a fixed string of length m, on each of these n strings there is a pointer on some character. Thei-th character displayed on the screen is the pointed character in the i-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).

During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index m, and when we move it to the right from the position m it moves to the position 1.

You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.

Input

The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols.

Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase English letters, and characters '#', '*' or '&'.

You have such input data that you can always get a valid password.

Output

Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.

Examples
input
3 4
1**2
a3*0
c4**
output
1
input
5 5
#*&#*
*a1c&
&q2w*
#a3c#
*&#*&
output
3
Note

In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.

In the second test one of possible algorithms will be:

  • to move the pointer of the second symbol once to the right.
  • to move the pointer of the third symbol twice to the right.

刚开始题意看错了,气啊,写了半天的bfs,宛如一个智障,

后来发现挺水的,保存每一个行这三个类型字符最近的距离,然后三层for循环组合找最小的

然而。。。还是wa了。。。。。。。。。。。。。。

找了半天也没找出错误,后来才发现定义的inf是0x3f3f3f3f,组合的时候三个数加起来,有可能会出现超int的情况。。。。

n和m都很小,inf不用定义很大

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#define ll long long  
#define inf 10000
using namespace std; 
char s[100][100];
int judge(int i,int j)
{
	if(s[i][j]>='0'&&s[i][j]<='9')
	{
		return 1;
	}
	if(s[i][j]>='a'&&s[i][j]<='z')
	return 2;
	if(s[i][j]=='#'||s[i][j]=='*'||s[i][j]=='&')
	return 0;
}
int main()
{
	int n,m,ans=inf,i,j,k,t1,t2,t3,t;
	int jvli[100][5];
	scanf("%d %d",&n,&m);
	for(i=0;i<100;i++)
	{
		for(j=0;j<4;j++)
		jvli[i][j]=inf;
	}
	for(i=0;i<n;i++)
	scanf("%s",s[i]);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			t=min(j,m-j);
			jvli[i][judge(i,j)]=min(jvli[i][judge(i,j)],t);
		}
	}
	
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			for(k=j+1;k<n;k++)
			{
				t1=min(jvli[i][1]+jvli[j][2]+jvli[k][0],jvli[i][0]+jvli[j][1]+jvli[k][2]);
				t2=min(jvli[i][1]+jvli[j][0]+jvli[k][2],jvli[i][0]+jvli[j][2]+jvli[k][1]);
				t3=min(jvli[i][2]+jvli[j][1]+jvli[k][0],jvli[i][2]+jvli[j][0]+jvli[k][1]);
				t=min(t1,min(t2,t3));
				ans=min(ans,t);
			}
		}
	}
	printf("%d\n",ans);
 } 


【YOLO系列】YOLOv11详解:模型结构、损失函数、训练方法及代码实现 YOLOv11在目标检测领域实现重大突破,通过动态骨干网络(Dyna-Backbone)和FPN++架构,在保持高帧率(≥60FPS)的同时提升小目标检测精度(AP_S提升5.6%)。创新采用CIoU++损失函数和类别平衡Focal Loss,结合Mosaic-Plus数据增强,参数量减少18%至6.5M。实验显示,该模型在COCO数据集上实现更高mAP,特别适合移动端部署,Jetson Xavier平台能耗比优化至3.2W·ms⁻¹,支持目标检测、实例分割等多任务场景。关键创新包括动态深度调整和双向特征金 阅读详情

相关推荐

广义平均(Generalized Mean, GeM)

本位介绍了广义平均操作的定义和简要推导,帮助大家理解其含义。

qq_45802280的博客 4547

【CodeForces - 761C】Dasha and Password (暴力可过,标解dp,字符串,有坑总结)

题干: After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: There is ...

xuanweiace的博客 790

tcl脚本语言之file的常见用法

这些命令覆盖了从文件属性获取、修改、复制、删除、路径处理等广泛的文件操作需求。命令用于处理文件系统操作。

hzmscut的博客 5149

CodeForces 761C Dasha and Password

CodeForces 761C Dasha and Password 不得不说这个是让我非常不明白,我总感觉这个题是可以不用暴力的。但是,偏偏很多人都是用暴力A过的.......我做的肯定是假codeforces。

ccutyear的博客 710

C# WPF多页面间的数据共享(经典)

实现页面间的数据共享有很多方法,比如:①事件的发布订阅 ②委托③ioc容器④静态类等,这节主要通过静态的集合实现数据的添加和获取。

sf315418的博客 639

PADS VX2.7学习记录06-PADS Router软件功能操作

PADS VX2.7学习记录06-PADS Router软件功能操作

qq_31444421的博客 7860

Codeforces 761C Dasha and Password 【模拟】

题目链接:http://codeforces.com/contest/761/problem/C   题意: 有 n 个字符串,每个字符串的长度是m,如果认定一个字符串是一个密码,则必须满足: 1:至少有1个数字。2:至少有一个小写字母。3:至少有一个 #、*或&amp; 现在有n个光标,每个光标指向这 n 个字符串。现在可以移动光标,最后使得所有光标指向的字符能组成一个密码。(字符串是...

BlueSky 629

Python编程基础05:运算符与表达式

文章目录一、算术运算符1、分类说明表2、注意事项3、案例演示任务1、计算成绩差与平均成绩课堂练习:编程处理带余除法。任务2、打印购物小票 运算符就是专门用于告诉程序执行特定运算或逻辑操作的符号。表达式是指由常量、变量和运算符组成的一个算式。编写程序对数据进行处理,其实处理就是对数据实施各种各样的运算,搞懂运算符与表达式是我们编写程序的基础性工作,本次讲课笔记通过案例讲解各种运算符的用法以及正确书写Python表达式的注意事项。 一、算术运算符 Python中的算术运算符就是用来处理四则运算的符号,也是

howard2005的专栏 3119

CodeForces - 761C Dasha and Password (思维 暴力)

       题意:给出n个字符串,每个串的初始光标都位于0(列)处,问你怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字符,密码至少包含3种字符:数字,小写字母,特殊符号)的情况下使得移动的光标步数最小。      题解:分别把数字、字母、3种字符定义为第0类、第1类、第2类。            b[i][j]  代表当取第i个字符串,取第j类字符的最小距离,b[i][0]...

hxxjxw的博客 324

dify进阶:使用 FastAPI 的 StreamingResponse 实现高效的数据流传输

在 FastAPI 框架中,是一个非常有用的工具,它允许你以流的方式发送数据给客户端,而不是一次性加载所有内容到内存中再发送。这对于处理大型文件下载、视频流或者任何需要长时间处理的任务特别有用。

xiezhipu的博客 1433

S速度曲线轨迹规划(普通变频位置闭环控制算法详细介绍+SCL代码)

位置控制用PD控制器,详细内容介绍请查看下面博客文章:PD控制器算法详细解读_RXXW_Dor的博客-优快云博客鉴于积分和微分在工程上的大量应用,这篇博文主要讲解工程上的如何求导f'(x),导数反映的是函数(信号)的变化率,牛顿也是在研究运动的时候提出了微积分的概念,我们知道反映位移变化的快慢程度是速度v(t),反映速度变化快慢程度的物理量是加速度(速度的变化率)。

RXXW_Dor的博客 3886

CodeForces 761C 【DP】

总结:能这么DP就这么写! 多练位运算标记。 #include<bits/stdc++.h> using namespace::std; const int N=55; const int INF=0x3f3f3f3f; int n, m, dp[N][2][2][2]; char s[N][N]; bool isdigit(char ch) { if(ch&...

weixin_30826095的博客 164

【异常】Coze/扣子 Workflow 调用报 4200 错误深度解析

Coze API 的。

奶爸的编程之路,也就一周冷个三天 301

Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

A man can be destroyed, but not defeated. 453

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforces Round #394 (Div. 2)(A. Dasha and Stairs,B. Dasha and friends,C. Dasha and Password)

题目链接 因为技术问题,这round排名崩了不算分,那就先来更新ABC题吧A. Dasha and Stairs 很多人被hacked应该是没有考虑a、b同时为0的情况,我也没注意啊#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespa

永远保持谦卑好学 474

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

[Codeforces Round #394 DIV2C (CF761C)] Dasha and Password

题意给定一个密码锁,密码锁有nn环,每一环mm个字符,你可以旋转每一环向左或向右,询问最少旋转几次能让现在的密码至少有一个数字,一个小写字母和一个给定符号(*或&或#) n,m≤50n,m\le 50题解对于每个环都找出来转到数字,字母,符号所需次数,n3n^3循环就完了,一道大水题。复杂度O(n3m)O(n^3m) 但是这题有更优算法。 我们对得到数字的次数取出最小的三个,字母和符号也是,这

ztx 439

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Codeforces Round #394 (Div. 2)C. Dasha and Password【暴力】

C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After overcoming the stairs Dasha came to class

mengxiang000000 530

Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力

C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password...

weixin_30299709的博客 116

Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)

http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字符,密码至少包含3种字符:数字,小写字母,特殊符号)的情况下使得移动的光标步数最小。 思路: 因为每个串只提供一个密码,所以我们先预处理计算出每个字符串3种字符的最少移动步数。 然后接下...

weixin_30274627的博客 120

Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)

C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After overcoming the stairs Dasha came to c...

weixin_33869377的博客 159
上一篇: 位运算详解及竞赛常见用法入门
下一篇: dd大牛的《背包九讲》(转)
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值