问题 B: Friendship of Mouse

时间限制: 1 Sec  内存限制: 64 MB
提交: 10  解决: 7

题目描述

Today in KBW, N mice from different cities are standing in a line. Each city is represented by a lowercase letter. The distance between adjacent mice (e.g. the 1st and the 2nd mouse, the N−1th and the Nth mouse, etc) are exactly 1. Two mice are friends if they come from the same city.

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 city of ith mice.

⋅ 1≤T≤50.

⋅ for 80% data, 1≤N≤100.

⋅ for 100% data, 1≤N≤1000.

⋅ 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 1 and y is the result. If there are no mice in same city, output −1 instead.

样例输入

2
abcecba
abc

样例输出

Case #1: 2
Case #2: -1

思路:

2015 ICPC 上海站F题,很水的一道打卡题,怎么做都行,N^2暴力都无所谓...

代码:

#include<iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1005
#define inf 99999
using namespace std;char str[maxn];int main ()
{//freopen("in.txt","r",stdin);int n;scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%s", str);int len = strlen(str);int ans = 99999;for (int q = 0; q < len; q++)for (int w = q + 1; w < len; w++) {if (str[q] == str[w])ans = min(ans, w - q);}if (ans == inf) ans = -1;printf("Case #%d: %d\n", i, ans);}return 0;
}

HHUOJ 1019 Friendship of Mouse(水题)相关推荐

  1. 22.10.25补卡 一堆cf水题

    被骂了, 写点水题泄泄愤 Problem - A - Codeforces 贪心, 排一下序, 每次选最大的, 选的同时记录一下已经拿了多少个硬币 /* ⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿ ...

  2. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  3. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  4. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  5. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  6. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  7. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  8. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  9. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  10. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

最新文章

  1. 多线程实现生产者消费者模型
  2. python终结一个循环额_Python语言入门之内存管理方式和垃圾回收算法解析
  3. 把脉Linux上USB数据流
  4. c __cplusplus详解
  5. 【简洁写法】剑指 Offer 30. 包含min函数的栈
  6. STRUTS2 标签调用静态方法
  7. 为什么到处都在推python_Python为什么能取得越来越超然的地位
  8. QQ音乐API分析之-加密参数分析(sign计算)
  9. limesurvey php5.2,Limesurvey二次开发(接入CAS统一身份认证)随笔
  10. 如何用计算机画出分子轨道图,常见的分子轨道图.pdf
  11. 详谈软件工程之软件开发方法
  12. AndrewNG机器学习听课笔记(1 )——线性回归(linear regression)
  13. 邮件协议POP3/IMAP/SMTP服务的区别 常用邮箱的 IMAP/POP3/SMTP 设置
  14. Windows 10x64 Pro Modified By Michael
  15. 荒野、车居生活与自由世界——读《车轮上的瓦尔登湖》
  16. 百度地图注册:申请百度地图秘钥
  17. ElasticSearch(Es的CURD)基本操作命令
  18. 云服务器搭建MQTT消息代理EMQX
  19. java可以微信qq同时登陆_java实现 微博登录、微信登录、qq登录实现代码_java_脚本之家...
  20. Python练习题 判断语句(19~36)

热门文章

  1. 【洛谷】P1428:小鱼比可爱
  2. 浏览器(Microsoft Edge)主页被360劫持的终极解决办法
  3. 各种水龙头拆卸图解_水龙头拆除和安装步骤图解
  4. C#将自定义的时间字符串直接转换为UTC世界协调时间
  5. Proxmox(PVE) Web 控制面板添加登录二步验证(TFA)
  6. 药店不停业盘点操作流程,海典盘点机PDA操作使用说明
  7. PAT乙级(Basic Level)练习题 星际密码[斐波那契][打表]
  8. JES专栏:Portlets的国际化和本地化(eNews 第二十八期/2007.09)
  9. 2020-03-11
  10. 009-Dockerfile-MAINTAINER(deprecate)-使用 LABEL 代替