Codeforces 761C DaSha and Password 暴力
来源:互联网 发布:网络流行aq是什么意思 编辑:程序博客网 时间:2024/06/07 00:43
点击打开链接
题意:给出n行string 长度都为m (n,m<=50),一个游标指向n行string的第一个字符, password长度为n 由n行string游标所指的字符组成,Password至少包含一个数字,字符和字母,移动游标消耗1 求最小消耗.
消耗最小,只需要有三行满足条件即可,多的没意义,,暴力O(n^3)枚举这三行,预处理每行变化的最小代价即可.
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e3+20;const int inf=1e5;char s[N][N];int d[N][3];//d[i][k] 第i行变为数字||字符||'*'#''&'的最小代价 int main(){int n,m;while(cin>>n>>m){for(int i=1;i<=n;i++){scanf("%s",s[i]+1);d[i][0]=d[i][1]=d[i][2]=inf;for(int j=1;j<=m;j++){if(s[i][j]>='0'&&s[i][j]<='9')d[i][0]=min(d[i][0],min(j-1,m+1-j));else if(s[i][j]>='a'&&s[i][j]<='z')d[i][1]=min(d[i][1],min(j-1,m+1-j));elsed[i][2]=min(d[i][2],min(j-1,m+1-j));}}//因为肯定有三行分别指向数字,字母和字符 n<=50暴力枚举这三行即可 int ans=inf;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(i==j) continue;for(int k=1;k<=n;k++){if(k==i||k==j) continue;int t=d[i][0]+d[j][1]+d[k][2];ans=min(ans,t);}}} cout<<ans<<endl; }return 0;}
0 0
- Codeforces 761C DaSha and Password 暴力
- Codeforces Round #394 (Div. 2)C. Dasha and Password【暴力】
- Codeforces 761C Dasha and Password 【模拟】
- Codeforces 761C-Dasha and Password
- 【Codeforces 761 C Dasha and Password 】
- CodeForces 761C Dasha and Password
- CodeForces 761C Dasha and Password
- Codeforces 761C Dasha and Password
- C. Dasha and Password(模拟,暴力)
- 【codeforces 761C】Dasha and Password(动态规划做法)
- 【codeforces 761C】Dasha and Password(贪心+枚举做法)
- Codeforces-Round 394#C-Dasha and Password'
- C. Dasha and Password-C. Dasha and Password-暴力|dp思想
- C. Dasha and Password
- 761C Dasha and Password[简单dp]
- 文章标题 coderforces 761C : Dasha and Password(贪心+暴力)
- Codeforces Round #394 (Div. 2) C. Dasha and Password
- Codeforces Round #394 (Div. 2) C. Dasha and Password
- C9-1 数组求和
- MySql binlog
- 字符串
- C9-2 折半查找
- ServletConfig和ServletContext接口
- Codeforces 761C DaSha and Password 暴力
- 孪生素数问题
- Leetcode 12. Integer to Roman
- Mysql备份与恢复
- mybatis缓存配置
- Codeforces Round #343 (Div. 2) C
- 128. Longest Consecutive Sequence
- Neutron Router 工作原理
- Codeforces Round #394 (Div. 2) C. Dasha and Password 贪心+预处理+枚举