Problem Description
N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance between adjacent frogs (e.g. the 1st and the2nd frog, the N−1th and the Nth frog, etc) are exactly . Two frogs are friends if they come from the same country.

The closest friends are a pair of friends with the minimum distance. Help us find that distance.
Input
First line contains an integer T, which indicates the number of test cases.

Every test case only contains a string with length N, and the ith character of the string indicates the country of ith frogs.

⋅ ≤T≤.

⋅ for % data, ≤N≤.

⋅ for % data, ≤N≤.

⋅ the string only contains lowercase letters.
 
Output
For every test case, you should output "Case #x: y", where x indicates the case number and counts from  and y is the result. If there are no frogs in same country, output − instead.
 
Sample Input
abcecba
abc
 
Sample Output
Case #:
Case #: -
 
Source

multiset随便搞搞就出来了。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1006
#define inf 1e12
multiset<int>ms[N];
multiset<int>::iterator it,it1,it2;
char s[N];
int main()
{
int t;
int ac=;
scanf("%d",&t);
while(t--){
for(int i=;i<N;i++){
ms[i].clear();
}
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++){
int u=s[i]-'a';
ms[u].insert(i);
}
int ans=;
for(int i=;i<;i++){
//it=ms[i].begin();
int minnn=;
int size_=ms[i].size();
int num=;
for(it1=ms[i].begin();it1!=ms[i].end();it1++){
if(size_==){
break;
}
if(num>=size_-){
break;
}
//printf("%d= %d\n",i,(*it1));
num++;
it2=it1; it2++;
int dis=(*it2)-(*it1);
if(dis<minnn){
minnn=dis;
}
}
//printf("minnn = %d\n",minnn);
ans=min(ans,minnn); }
printf("Case #%d: ",++ac);
if(ans==){
printf("-1\n");
}else
printf("%d\n",ans);
}
return ;
}

hdu 5578 Friendship of Frog(multiset的应用)的更多相关文章

  1. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  2. hdu 5578 Friendship of Frog

    题意:给定一行字符串(都是小写字母),每一个字符都代表一只青蛙以及其国籍,若字符串中出现两个字符相同,则这两个字符所代表的青蛙来自同一国度,可称之为好朋友. 现在需要找到距离最近的好朋友并输出他们的距 ...

  3. hdu-5578 Friendship of Frog(暴力)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5578 Friendship of Frog Time Limit: 2000/1000 MS (Jav ...

  4. Friendship of Frog(水题)

    Friendship of Frog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  5. 【HDU 5578】Friendship of Frog

    题 题意 求相同字母最近距离 分析 用数组保存各个字母最后出现的位置,维护最小距离. 代码 #include <cstdio> int c[30],n,p,a,minl; char ch; ...

  6. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  7. HDU 4302 Holedox Eating(multiset)

    http://acm.hdu.edu.cn/showproblem.php?pid=4302 题意: 在一条直线上,会有多条命令,如果是0,那么就会在x位置处出现一个蛋糕,如果是1,某人就会找到最近的 ...

  8. HDU 4022 Bombing (map + multiset)

    题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b    a == ...

  9. hdu 4268 Alice and Bob(multiset|段树)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. GO学习资源站

    GO语言学习资源网站 http://golangtc.com https://gobyexample.com http://golang-examples.tumblr.com

  2. linux之SQL语句简明教程---HAVING

    那我们如何对函数产生的值来设定条件呢?举例来说,我们可能只需要知道哪些店的营业额有超过 $1,500.在这个情况下,我们不能使用 WHERE 的指令.那要怎么办呢?很幸运地,SQL 有提供一个 HAV ...

  3. iOS Xcode工程目录的 folder 和 group的区别(蓝色和黄色文件夹的区别)

    1. 来自 http://blog.csdn.net/fanjunxi1990/article/details/9352917 XCode工程目录里面,有时你会发现2个不同颜色的文件夹,一种是蓝色的, ...

  4. Linux内核中常见内存分配函数(二)

    常用内存分配函数 __get_free_pages unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order) __get_f ...

  5. Quartz框架的使用

    专用词汇:scheduler:任务调度器trigger:触发器,用于定义任务调度时间规则job:任务,即被调度的任务misfire:错过的,指本来应该被执行但实际没有被执行的任务调度 Quartz核心 ...

  6. xml中,button改变背景颜色方法

    在画几个设置界面,用到了button控件,对于button空间的背景色在不同状态下的颜色改变方法,做了一下尝试,发现了两种背景颜色改变的方法,就总结了下. 方法一尝试了好多遍才好,要点在于,在sele ...

  7. 格而知之1:UIButton中imageView和titleLabel的位置调整

    在使用UIButton时,有时候需要调整按钮内部的imageView和titleLabel的位置和尺寸.在默认情况下,按钮内部的imageView和titleLabel的显示效果是图片在左文字在右,然 ...

  8. hdu 4521 线段树改点求点的应用

    小明系列问题——小明序列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  9. web Form 表单method="get" method="post" 区别

    get和post方法的不同 在B/S应用程序中,前台与后台的数据交互,都是通过HTML中Form表单完成的.Form提供了两种数据传输的方式——get和post.虽然它们都是数据的提交方式,但是在实际 ...

  10. Apache 日志配置,包含过滤配置

    最近排查支付宝交易成功后异步通知执行失败的原因,需要查看Apache的日志,发现之前一直没对日志进行设置,结果日志文件都1.5G多了,于是搜索了如何按天记录日志. 但公司的网站是通过阿里云的SLB分发 ...