hdu-5578 Friendship of Frog(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5578
Friendship of Frog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 556 Accepted Submission(s): 355
The closest friends are a pair of friends with the minimum distance. Help us find that distance.
Every test case only contains a string with length N, and the ith character of the string indicates the country of ith frogs.
⋅ 1≤T≤50.
⋅ for 80% data, 1≤N≤100.
⋅ for 100% data, 1≤N≤1000.
⋅ the string only contains lowercase letters.
abcecba
abc
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char str[];
int main()
{
int t;
scanf("%d",&t);
int cnt=;
while(t--)
{
scanf("%s",str);
int len=strlen(str);
int ans=,flag=;
for(int i=;i<len;i++)
{
for(int j=i+;j<len;j++)
{
if(str[j]==str[i])
{
ans=min(ans,j-i);
flag=;
break;
}
}
}
if(!flag)ans=-;
printf("Case #%d: %d\n",cnt++,ans);
}
return ;
}
hdu-5578 Friendship of Frog(暴力)的更多相关文章
- 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(multiset的应用)
Problem Description N frogs . Two frogs are friends if they come from the same country. The closest ...
- hdu 5578 Friendship of Frog
题意:给定一行字符串(都是小写字母),每一个字符都代表一只青蛙以及其国籍,若字符串中出现两个字符相同,则这两个字符所代表的青蛙来自同一国度,可称之为好朋友. 现在需要找到距离最近的好朋友并输出他们的距 ...
- Friendship of Frog(水题)
Friendship of Frog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 2920 分块底数优化 暴力
其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...
- 【HDU 5578】Friendship of Frog
题 题意 求相同字母最近距离 分析 用数组保存各个字母最后出现的位置,维护最小距离. 代码 #include <cstdio> int c[30],n,p,a,minl; char ch; ...
- hdu 5277 YJC counts stars 暴力
YJC counts stars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 5762 Teacher Bo (暴力)
Teacher Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...
- hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
随机推荐
- python#模拟发送电子邮件
#-*- coding:utf-8 -*- #模拟发送电子邮件 from email.mime.text import MIMEText from_addr = 'aa@sss.com' passwo ...
- 浏览器登录cookie
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- Apache启动失败(Windows 无法在本地计算机启动Apache2.2)
该问题产生的原因有很多,这里就说说我遇到的问题: 这个问题是突然遇到的,启动的时候连日志都没有产生,最后是通过window的日志中发现问题所在的,如图所示: 发现是目录错了.其他问题也可以通过该日志找 ...
- ASP.NET中指定自定义HTTP响应标头
新建一个类HideServerHeaderHelper,继承 IHttpModule,然后重写 OnPreSendRequestHeaders,Dispose,Init方法,如下代码所示 using ...
- 2015年11月26日 Java基础系列(七)正则表达式Regex
package com.demo.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @autho ...
- TensorFlow 初级教程(三)
TensorFlow基本操作 import os import tensorflow as tf os.environ[' # 使用TensorFlow输出Hello # 创建一个常量操作( Cons ...
- (转)基于libRTMP的流媒体直播之 AAC、H264 推送
参考: 1,基于libRTMP的流媒体直播之 AAC.H264 推送 http://billhoo.blog.51cto.com/2337751/1557646
- matlab + c/c++ opencv 混合编程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...
- SQL优化小结
一 背景 客户数据库经常出现死锁.超时.查询慢等问题,数据库mssql,数据量主要表大概上千W. 二 收集信息 首先是要找出IO大.查询慢.使用频率高的脚本.直接用Profiler ...
- Blobstore Java API overview
Blobstore API允许你的应用程序使用(serve)叫做Blobs的数据对象.这种数据对象比Datastore服务所允许的对象的尺寸大得多.Blobs能有效地为大文件比如视频.图片提供服务,允 ...