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 ...
随机推荐
- 简单的积雪shader
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' Shader "Custom/CoverSnow&q ...
- 2016 acm香港网络赛 B题. Boxes
原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N ...
- TortoiseSVN与VisualSVN Server搭建SVN版本控制系统(转)
地址:http://www.cnblogs.com/xing901022/p/4399382.html
- PHP-Manual的学习----【语言参考】----【类型】-----【array数组】
1.Array 数组 PHP 中的 数组 实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.此类型在很多方面做了优化,因此可以把它当成真正的数组,或列表(向量),散列表(是 ...
- Delphi Property详解
http://anony3721.blog.163.com/blog/static/51197420107105132120/?ignoreua Property Keyword Defines co ...
- vue实现简易留言板
首先引入vue.js <script src="vue.js"></script> 布局 <div id="div"> &l ...
- Inside a super fast CSS engine: Quantum CSS (aka Stylo)
https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/?utm_source=d ...
- 【python】-- RabbitMQ 安装、基本示例、轮询机制
RabbitMQ MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端consumer则可 ...
- ubuntu安装pip和python
安装pip2sudo apt-get install pip 这样安装的是pip2不支持Python3.x,可以使用如下命令安装pip3 sudo apt-get install python3-pi ...
- 图片加载控件Fresco
使用教程:https://www.fresco-cn.org/docs/index.html https://github.com/facebook/fresco application初始化fre ...