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 ...
随机推荐
- android TextView EditTextView一些技巧使用 (视图代码布局)
android TextView 是最常用的控件 可以用作普通的显示,还可以用作有显示文字的按钮,用作有显示图片的图文组合 1. 图文组合 xml 中: <TextView android:id ...
- 【配置】如何配置Tp-link无线路由器作为无线交换机
最近刚装了电信天翼宽带,谁知道现在只能装光猫.你说一个4M带宽有必要用光猫么?装好之后问题来了,这个光猫很奇葩,只有一个以太网接口,确有内置有路由功能,也就是只有一个出口的路由器.现在问题来了:我想接 ...
- js设计模式
http://www.csdn.net/article/2011-09-02/303983 阐明JavaScript设计模式.CSDN研发频道对此文进行了整理选取部分内容,供开发者学习.参考. 内容如 ...
- bash 学习笔记(一)
尽量使用printf而不要用echo(echo再不同情况下语义不同) 整数%d,小数后6位%f,科学计数法 %e,16进制 %x 宽度限制 %8s %-15s 正数朝右对齐 负数朝左对齐:%04d\n ...
- Number Sequence(kmp)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- PHP-xml-1
SimpleXML 解析xml 假设xml没有声明encoding默认使用utf-8进行解码.终于得到的数据编码为utf-8格式. 我猜想它内部实现了iconv(encoding='utf-8', ' ...
- PHP高级特性基础
php对象在内存中的区域:php对象名和对象存放的位置是不一样的,这一点和java是一模一样的,所以在php面向对象部分你完全可以套用java的思想去做.对象存放在堆区(heap)而对象名则和其他普通 ...
- 月赛-Crackhash
Crackhash 这个题目是我为月赛出的,完全仿照自mma 1st simple_hash. 这道题目比较有意思的地方在于在32位的程序中模拟了64位的算术运算. 题目的思路很清晰.要求输入全为数字 ...
- plaidctf2015 uncorrupt png
代码的执行时间挺长的,好囧! 参考了https://13c5.wordpress.com/2015/04/20/plaidctf-2015-png-uncorrupt/的代码 通过这个题目,也对Png ...
- Open Replicator
Open Replicator ( http://code.google.com/p/open-replicator/ ) 开源了.Open Replicator是一个用Java编写的MySQL bi ...