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. Python——列表操作

    一.列表中所有元素出现的次数,并输出为字典模式 def count_list(list): b_list = {} for i in set(list): b_list[i] = list.count ...

  2. 使用 Travis CI 自动部署 Hexo 站点至 GitHub Pages

    Hexo 与 GitHub Pages 安装配置请参考:Hexo 与 GitHub Pages 本文源码与生成的静态文件在同一项目下,源码在 source 分支,静态文件在 master 分支 新增 ...

  3. 9.Pod控制器概念和基本操作2

    利用一个简单的例子来启动一个deployment的Pod控制器 [root@master song]# cat deploy.yml apiVersion: apps/v1 kind: Deploym ...

  4. codeforces982F

    The Meeting Place Cannot Be Changed CodeForces - 982F Petr is a detective in Braginsk. Somebody stol ...

  5. 了解AutoCAD对象层次结构 —— 2 ——文档

    再次想象另外一个场景:启动AutoCAD程序后,您新建了两个.dwg文件,也就是说创建了两个文档(Document)对象.将窗口进行层叠,您看到的窗口应该与下图类似: 图 4‑3 如何访问这些文档呢? ...

  6. kubernetes 创建系统用户来支持访问 dashboard

    Dashboard: 1.部署: 下载yaml文件  可以直接运行也可以下载下来kubectl apply -f https://raw.githubusercontent.com/kubernete ...

  7. Android 永久保存简单数据

    转载: http://blog.csdn.net/xzlawin/article/details/45959033 方法1: 存数据: SharedPreferences userInfo = thi ...

  8. P1601 A+B Problem(高精)

    原题链接 https://www.luogu.org/problemnew/show/P1601 这个题提示的很清楚,并非简单的A+B,单纯的long  long型也不行(不要被样例所迷惑).因为lo ...

  9. Bomb Game HDU - 3622(二分最小值最大化)

    题意: 就是给出n对坐标,每对只能选一个,以选出来的点为圆心,半径自定义,画圆,而这些圆不能覆盖,求半径最小的圆的最大值 解析: 看到最x值最x化,那二分变为判定性问题,然后...然后我就没想到... ...

  10. miller——rabin判断素数

    我们首先看这样一个很简单的问题:判定正整数\(n\)是否为素数 最简单的做法就是枚举\(2\)到\(n\)的所有数,看是否有数是\(n\)的因数,时间复杂度\(O(n)\) 稍微优化一下发现只要枚举\ ...