hdu 5578 Friendship of Frog 2015ACM/ICPC亚洲区上海站-重现赛
来源:互联网 发布:tsp 遗传算法 java 编辑:程序博客网 时间:2024/04/30 10:12
将同一个country的frog放在一起,按照index从小到大排序。因此minimum distance一定出现在相邻的两个frog中。
#include<iostream>#include<stdio.h>#include<cstdio>#include<string>#include<cmath>#include<stdlib.h>#include<algorithm>#include<string.h>#include<cstring>#include<vector>#include<queue>#include<map>using namespace std;//hdu 5578const int maxn=1010;const int INF=0x3f3f3f3f;int T;int N;int ans;class frog{public: int country; int idx;public: frog() { country=0; idx=0; } frog(int c,int id) { country=c; idx=id; } bool operator <(const frog a) const { return idx<a.idx; }};vector<frog>mp[27];int main(){ freopen("input.txt","r",stdin); scanf("%d",&T); for(int ca=1;ca<=T;ca++) { char str[maxn]; memset(mp,0,sizeof(mp)); scanf("%s",&str); for(int i=0;i<strlen(str);i++) { mp[str[i]-'a'].push_back(frog(str[i]-'a',i+1)); } ans=INF; for(int i=0;i<26;i++) { sort(mp[i].begin(),mp[i].end()); for(int j=1;j<mp[i].size();j++) { ans=min(ans,mp[i][j].idx-mp[i][j-1].idx); } } if(ans==INF) ans=-1; printf("Case #%d: %d\n",ca,ans); }}
0 0
- hdu 5578 Friendship of Frog 2015ACM/ICPC亚洲区上海站-重现赛
- HDU 5578 Friendship of Frog(暴力)——2015ACM/ICPC亚洲区上海站
- HDU 5578.Friendship of Frog【字符串相同字符最近距离】【2015ACM/ICPC亚洲区上海站】【12月30】
- hdu 5583 Kingdom of Black and White 2015ACM/ICPC亚洲区上海站-重现赛
- HDU-5583-Kingdom of Black and White(2015ACM/ICPC亚洲区上海站-重现赛)
- hdu 5584 LCM Walk 2015ACM/ICPC亚洲区上海站-重现赛
- HDU 5572 An Easy Physics Problem(计算几何)——2015ACM/ICPC亚洲区上海站-重现赛
- HDU-5578-Friendship of Frog【2015上海赛区】
- HDU-5578-Friendship of Frog【2015上海赛区】(水题)
- 2015 上海区域赛 Friendship of Frog
- 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学) HDU 5512 Pagodas
- 【hdu 5521】【 2015ACM/ICPC亚洲区沈阳站重现赛】Meeting 题意&题解&代码
- HDU 5512 Pagodas 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
- hdu 5510 Bazinga 2015ACM/ICPC亚洲区沈阳站-重现赛
- hdu 5521 Meeting 2015ACM/ICPC亚洲区沈阳站-重现赛
- HDU 5512 Pagodas (GCD博弈 + 2015ACM/ICPC亚洲区沈阳站-重现赛)
- HDU-5512 Pagodas(GCD)(2015ACM/ICPC亚洲区沈阳站-重现赛)
- hdu 5131 Song Jiang's rank list 2014ACM/ICPC亚洲区广州站-重现赛
- 三十分钟掌握STL
- OpenCV3.1开发系列-OpenCV2.4.13更新介绍
- ORMlite多表关联查询实现
- Python中获取某个用户对某个文件或目录的访问权限
- java线程中断方式
- hdu 5578 Friendship of Frog 2015ACM/ICPC亚洲区上海站-重现赛
- 深入理解Java:注解(Annotation)基本概念
- thinkphp控制器变量在模板中显示
- NoSQL之Morphia操作MongoDB
- 指针数组和数组指针
- 把玩之python爬虫urllib2高级篇
- 【Android】31、常见控件的使用方法——ProgressBar
- 学习笔记 2016年6月17日 09:01:19
- axure URL