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 ...
随机推荐
- angualejs
http://segmentfault.com/a/1190000000347412 http://www.xker.com/page/e2015/06/199141.html http://www. ...
- 编辑器模式下如何实例化Prefab
当我们在EditMode下需要用脚本批量添加prefab时,可以用 PrefabUtility.InstantiatePrefab(prefab) as GameObject; 注意:如果用GameO ...
- swift中的?和!理解
本文转载至 http://www.cnblogs.com/dugulong/p/3770367.html 首先贴cocoachina上某位大大的帖子: Swift语言使用var定义变量,但和别 ...
- Educational Codeforces Round 1 (C) (atan2 + long double | 大数)
这题只能呵呵了. 东搞西搞,折腾快一天,最后用了一个800多行的代码AC了. 好好的题目你卡这种精度干啥. 还有要卡您就多卡点行不,为什么long double 又可以过... 废了N长时间写个了不管 ...
- SQL SERVER 2008查看sql执行的时间
set statistics profile onset statistics io onset statistics time ongo<这里写上你的语句...>goset statis ...
- POJ 2856 Y2K Accounting Bug【简单暴力】
链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...
- 解决iOS11 UIScrollView下移问题
iOS11 系统为UIScrollView增加一个contentInsetAdjustmentBehavior属性,默认为UIScrollViewContentInsetAdjustmentAutom ...
- less (css预处理)
用法 1. 必须在head内 2. 样式文件必须先加载 <head> <meta charset='utf-8'> <link rel="stylesheet/ ...
- 【学员管理系统】0x04 数据库连接优化
[学员管理系统]0x04 pymysql数据库连接优化 写在前面 项目详细需求参见:Django项目之[学员管理系统] 优化实现 把操作封装成函数 我们之前使用pymysql操作数据库的操作都是写死 ...
- LDA中的先验知识
LDA涉及到的先验知识有:二项分布.Gamma函数.Beta分布.多项分布.Dirichlet分布.马尔科夫链.MCMC.Gibbs Sampling.EM算法等. 二项分布 二项分布是N重伯努利分布 ...