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. UIDatePicker控件

    UIDatePicker继承关系如下: UIDatePicker-->UIControl-->UIView-->UIResponder-->NSObject 1.创建UIDat ...

  2. Elf 32

    [CentOS]安装软件:/ld-linux.so.2: ELF interpreter解决   环境: [orangle@localhost Downloads]$ uname -m&&am ...

  3. 【MYSQL 清空所有的的表中的数据的SQL的生成】

    MYSQL 清空所有的的表中的数据的SQL的生成 select Concat('TRUNCATE TABLE ', TABLE_NAME, ';') from INFORMATION_SCHEMA.T ...

  4. accel-pptp 部署

    accel-pptp 是 pptp-client 和 pptpd 的改进版,使用内核 pptp 模块,相比 raw socket 实现方式能提供更好的性能.   Ubuntu 12.04 上启用内核 ...

  5. RHEL 6.3使用CentOS yum源 (redhat yum安装失败)

    由于Redhat的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件.所以yum install 命令每次都安装失败 下面介绍一种更改yum源的方式: 系统说明: 系统:Red ...

  6. [置顶] ASP.Net中服务器控件的生命周期

    (1)初始化:在此阶段中,主要完成两项工作:一.初始化在传入Web请求生命周期内所需的设置;二.跟踪视图状态.首先,页面框架通过默认方式引发Init事件,并调用OnInit()方法,控件开发人员可以重 ...

  7. 网易云课堂_Linux操作系统入门(嵌入式开发零基础Ⅰ)_章节4:SHELL 环境

    课时44命令别名 命令别名 命令别名的概念: 命令别名的查看:alias 命令别名的设置:alias myls='ls -a' 课时45通配符 通配符 通配符都概念: 通配符是代表字符通用匹配的一种系 ...

  8. poj2488 A Knight's Journey

      A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24840   Accepted:  ...

  9. C++ STL源代码学习(map,set内部heap篇)

    stl_heap.h ///STL中使用的是大顶堆 /// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap ...

  10. 使用javascript oop开发滑动(slide) 菜单控件

    这里使用原生的javascript,用面向对象的方式创建一个容易维护使用方便的滑动菜单 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tra ...