hdu5578_Friendship of Frog_思维
来源:互联网 发布:知道mac地址能干什么 编辑:程序博客网 时间:2024/05/21 03:54
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5578
题目大意:让你找出两个相同字母间的最小距离。
解题思路:
对字母组进行标记,出现过的字母标记下,并记下位置,再次出现的时候计算一下与上一次距离,然后更新最小距离就行
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;const int inf=0x3f3f3f3f;int main(){ int t; int a[30],d[30],new1[30]; char str[1005]; scanf("%d",&t); int cas=0; while(t--) { int mnn=inf; memset(a,0,sizeof(a)); memset(d,0,sizeof(d)); memset(new1,0,sizeof(new1)); scanf("%s",str); int len= strlen(str); for(int i=0;i<len;i++) { int tmp=str[i]-'a'; if(!a[tmp]) { a[tmp]=1; } else { d[tmp]=i-new1[tmp]; mnn=min(mnn,d[tmp]); } new1[tmp]=i; } printf("Case #%d: ",++cas); if(mnn!=inf) printf("%d\n",mnn); else printf("-1\n"); } return 0;}
阅读全文
0 0
- hdu5578_Friendship of Frog_思维
- Number of numbers [思维]
- zoj3784 String of Infinity 思维。。。
- 思维简图(Thinking of)
- UVA 11292-Dragon of Loowater (思维)
- UESTC - 1263:The Desire of Asuna【思维】
- 思维 csu1697 Surface Area of Cubes
- CSU 1697 Surface Area of Cubes (思维)
- Codeforces 660D Number of Parallelograms 【思维】
- ZOJ 2975 Kinds of Fuwas【思维】
- zoj--3872--Beauty of Array(思维)
- 【LightOJ】1189 - Sum of Factorials(思维)
- lightoj-1189-Sum of Factorials【思维】
- Codeforces 667B - Coat of Anticubism(思维)
- Organizing Containers of Balls----思维题
- H. Streets of Working Lanterns----思维题
- Codeforces 466C Number of Ways【思维】
- codeforces Minimum number of steps 思维
- Vue.js+Layer表格数据绑定与实现更新
- Vue.js 表格查询与更新
- jqGrid 帮助文档
- spring boot(8)-mybatis三种动态sql
- 网上的画板代码收集和整理
- hdu5578_Friendship of Frog_思维
- Spring 给bean配置list<bean>列表参数
- 15.1, 15.2, 15.3, 15.5
- Git 笔记
- 在jsp中用ajax向action传值为空 JSP中确定有值
- MVP+Retrofit+RxJava+Okhttp拦截器
- Ubuntu 搜索文件的方法
- NUC1013 阶乘结果末尾有多少零【分析思维】
- AMD phenom(翼龙) x4 955 黑苹果(El Capital 10.11.6)安装成功记录