hdu 5578 Friendship of Frog(multiset的应用)
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.
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.
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.
abcecba
abc
Case #:
Case #: -
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的应用)的更多相关文章
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- hdu 5578 Friendship of Frog
题意:给定一行字符串(都是小写字母),每一个字符都代表一只青蛙以及其国籍,若字符串中出现两个字符相同,则这两个字符所代表的青蛙来自同一国度,可称之为好朋友. 现在需要找到距离最近的好朋友并输出他们的距 ...
- hdu-5578 Friendship of Frog(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5578 Friendship of Frog Time Limit: 2000/1000 MS (Jav ...
- Friendship of Frog(水题)
Friendship of Frog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- 【HDU 5578】Friendship of Frog
题 题意 求相同字母最近距离 分析 用数组保存各个字母最后出现的位置,维护最小距离. 代码 #include <cstdio> int c[30],n,p,a,minl; char ch; ...
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- HDU 4302 Holedox Eating(multiset)
http://acm.hdu.edu.cn/showproblem.php?pid=4302 题意: 在一条直线上,会有多条命令,如果是0,那么就会在x位置处出现一个蛋糕,如果是1,某人就会找到最近的 ...
- HDU 4022 Bombing (map + multiset)
题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b a == ...
- hdu 4268 Alice and Bob(multiset|段树)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- Oracle EBS-SQL (BOM-16):检查多层BOM.sql
select rownum seq_num, lpad(to_char(level), decode(level, 1, 1, level + 1), '.') bom_level, bbm.ASSE ...
- 基于HCE移动支付研究报告
1. 概念 HCE(host-based card emulation),即基于主机的卡模拟.在一部配备NFC功能的手机实现卡模拟,目前有两种方式:一种是基于硬件的,称为虚拟卡模式(Virtual C ...
- ca 证书、签名
1.我现在没有个人CA证书,使用.中信建投网上交易,是如何保障安全的呢? 如果您目前没有个人CA证书,使用.中信建投网上交易,系统其实也是用CA证书的RSA体系进行加密的. 您在输入账户和密码进行登录 ...
- Qt 鼠标样式特效探索样例(一)——利用时间器调用QWidget.move()函数
Qt 鼠标样式特效探索样例(一) 心血来潮,突然想在Qt里玩一把鼠标样式,想到在浏览网页时,经常看到漂亮的鼠标动画,于是今天摸索着乱写个粗糙的demo,来满足自己的好奇心. 效果图 方案要 ...
- Java GC 日志详解(转)
Java GC日志可以通过 +PrintGCDetails开启 以ParallelGC为例 YoungGC日志解释如下(图片源地址:这里) : FullGC(图片源地址:这里): http://blo ...
- jquery获取复选框
Html代码: <input type="checkbox" name="chekItem" /> checkbox1 <br /> & ...
- 命名空间“System.Windows.Forms”中不存在类型或命名空间名称“DataVisualization”。是否缺少程序集引用?
using System.Windows.Forms.DataVisualization.Charting; 编译时报警:命名空间"System.Windows.Forms"中不存 ...
- MatLab实现FFT与功率谱
FFT和功率谱估计 用Fourier变换求取信号的功率谱---周期图法 clf; Fs=1000; N=256;Nfft=256;%数据的长度和FFT所用的数据长度 n=0:N-1;t=n/Fs;%采 ...
- sublime text 2 安装
下载 http://pan.baidu.com/s/1eRemu0y http://jingyan.baidu.com/album/ff4116259b057c12e48237b8.html?pici ...
- javascript的几种时间格式
1.当前系统区域设置格式(toLocaleDateString和toLocaleTimeString) 例子:(new Date()).toLocaleDateString() + " &q ...