Crazy Search
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3035    Accepted Submission(s): 1133
 
 
Problem Description
Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in a given text. Such number could be the number of different substrings of a given size that exist in the text. As you soon will discover, you really need the help of a computer and a good algorithm to solve such a puzzle.
 
Your task is to write a program that given the size, N, of the substring, the number of different characters that may occur in the text, NC, and the text itself, determines the number of different substrings of size N that appear in the text.
 
As an example, consider N=3, NC=4 and the text "daababac". The different substrings of size 3 that can be found in this text are: "daa", "aab", "aba", "bab", "bac". Therefore, the answer should be 5.
 
Input
The first line of input consists of two numbers, N and NC, separated by exactly one space. This is followed by the text where the search takes place. You may assume that the maximum number of substrings formed by the possible set of characters does not exceed 16 Millions.
 
Output
The program should output just an integer corresponding to the number of different substrings of size N found in the given text.
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
 
The output format consists of N output blocks. There is a blank line between output blocks.
 
 
Sample Input
1
3 4
daababac
 
Sample Output
5
 
#include<iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
int t,n,nc;
cin>>t;
map<string,int> m;
while(t--){
cin>>n>>nc;
m.clear(); //要格式化。
string str;
cin>>str;
string temp;
int i,length;
length=str.length();
for(i=0;i<=length-n;i++)
{
temp=string(str,i,n); //截取字符串(要记住)
if(m.count(temp)==0)
m[temp]++;
}
cout<<m.size()<<endl;
}
return 0;
}
 
 

(map string)Crazy Search hdu1381的更多相关文章

  1. STL——容器(Map & multimap)的插入与迭代器

    1. 容器(Map & multimap)的插入 map.insert(...);    //往容器插入元素,返回pair<iterator,bool> map中插入元素的四种方式 ...

  2. 斗地主的综合案例实现(Map有序)

    斗地主的综合案例实现(Map有序) 整体思路 代码实现 import java.util.ArrayList; import java.util.Collections; import java.ut ...

  3. 分布式基础学习(2)分布式计算系统(Map/Reduce)

    二. 分布式计算(Map/Reduce) 分 布式式计算,同样是一个宽泛的概念,在这里,它狭义的指代,按Google Map/Reduce框架所设计的分布式框架.在Hadoop中,分布式文件 系统,很 ...

  4. 分布式基础学习【二】 —— 分布式计算系统(Map/Reduce)

    二. 分布式计算(Map/Reduce) 分布式式计算,同样是一个宽泛的概念,在这里,它狭义的指代,按Google Map/Reduce框架所设计的分布式框架.在Hadoop中,分布式文件系统,很大程 ...

  5. IntelliJ IDEA中,mybatis的配置文件(map.xml)无法编译到class文件夹下

    编译工具:IntelliJ IDEA 项目结构:maven 项目框架:SSM 问题:java目录下,mybatis的配置文件(map.xml)无法编译到class文件夹下 问题原因:在idea中,直接 ...

  6. C++实现switch匹配字符串string(map方法)

    如果语法中大量使用if...else语句会造成代码臃肿,if语句C++语法中switch...case中case只能是整形变量,这里提供了一种思路,用map方法使健与值对应,这样字符串string类型 ...

  7. POJ 2153 Rank List (map映射)

    水题,竟然花了那么多时间...主要是不知道为什么,明明在本机上编译过去了,但是用c++提交却编译错误...最后用g++提交AC 题意:给出n个学生的名字,然后给出m个测验. 每个测验给出n个学生的分数 ...

  8. HDU 4022 Bombing (map + multiset)

    题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b    a == ...

  9. 09--STL关联容器(map/multimap)

    一:map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺 ...

随机推荐

  1. VS2017设置背景主题

    一.VS2017设置背景主题 1.下载并安装Color Theme Editor for Visual Studio 2017和MoeIDE (图中红圈中的两个插件,工具-扩展和更新-联机-右上角搜索 ...

  2. C-Lodop对大小写敏感 不要使用大小混写

    C-Lodop是对大小写敏感的,而以前的Lodop控件,对于大小混写有可能可以用,而目前由于高版本的火狐谷歌不再支持np插件,为了兼容所有浏览器,就要使用c-lodop,或像Lodop官网的样例一样, ...

  3. 使用proxychains 代理终端

    最近在国外的vps上搭建了一个ss服务器,在浏览器里面设置socks5代理上网很方便, 但是终端里面却只支持http方式的代理配置,网上有socks转http代理的方式,但是最近发现一个更为简单的方式 ...

  4. Nginx 接受上游缓存流程

    L:101 这个指令主要是由上游服务器来决定是否缓存 详见博客Nginx 针对上游服务器缓存

  5. 了解AutoCAD对象层次结构 —— 3 ——数据库

    数据库的结构是什么样的?对象是如何存储在数据库中的?这些问题我们需要搞明白.在此我们可以借助工具ArxDbg或MgdDbg来查看数据库结构及其内容.下图就是利用MgdDbg工具查看到的内容,我们可以看 ...

  6. python之旅六【第七篇】面向对象

    面向对象三大特性 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强... 面向对象编程 ...

  7. Codeforces Round #518 (Div. 2) B. LCM gcd+唯一分解定律

    题意:给出b 求lcm(a,b)/a 在b从1-1e18有多少个不同得结果 思路lcm*gcd=a*b  转换成    b/gcd(a,b) 也就是看gcd(a,b)有多少个值  可以把b 由唯一分解 ...

  8. Codeforces519 E. A and B and Lecture Rooms

    传送门:>Here< 题意:询问给出一棵无根树上任意两点$a,b$,求关于所有点$i$,$dist(a,i) = dist(b,i)$的点的数量.要求每一次询问在$O(log n)$的时间 ...

  9. 【BZOJ3771】Triple 生成函数 FFT 容斥原理

    题目大意 有\(n\)把斧头,不同斧头的价值都不同且都是\([0,m]\)的整数.你可以选\(1\)~\(3\)把斧头,总价值为这三把斧头的价值之和.请你对于每种可能的总价值,求出有多少种选择方案. ...

  10. 基于 __new__ 方法的单例模式

    单例模式定义 首次实例化创建实例化对象 之后的每次实例化都用最初的实例化对象 即单实例模式 __new__ 的原理 __new__ 方法可以在 __init__ 方法执行 这样可以在初始化之前进行一系 ...