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(); // Format .
string str;
cin>>str;
string temp;
int i,length;
length=str.length();
for(i=0;i<=length-n;i++)
{
temp=string(str,i,n); // Intercepting string ( Remember )
if(m.count(temp)==0)
m[temp]++;
}
cout<<m.size()<<endl;
}
return 0;
}
 
 

(map string)Crazy Search hdu1381 More articles about

  1. STL—— Containers (Map &amp; multimap) The insertion and iterator of

    1.  Containers (Map & multimap) Insertion map.insert(...);    // Insert elements into the container , return pair<iterator,bool> map There are four ways to insert elements in the ...

  2. Distributed basic learning (2) Distributed computing system (Map/Reduce)

    Two .  Distributed computing (Map/Reduce) branch Cloth calculation , It's also a broad concept , ad locum , It refers to in a narrow sense , Press Google Map/Reduce Framework designed by the distributed framework . stay Hadoop in , Distributed file System , very ...

  3. Distributed basic learning 【 Two 】 —— Distributed computing system (Map/Reduce)

    Two . Distributed computing (Map/Reduce) Distributed computing , It's also a broad concept , ad locum , It refers to in a narrow sense , Press Google Map/Reduce Framework designed by the distributed framework . stay Hadoop in , distributed file system , It's a long way ...

  4. IntelliJ IDEA in ,mybatis Configuration file for (map.xml) Unable to compile to class Under the folder

    Compiler tools :IntelliJ IDEA Project structure :maven The project framework :SSM problem :java Under the table of contents ,mybatis Configuration file for (map.xml) Unable to compile to class Under the folder Question why : stay idea in , direct ...

  5. POJ 2153 Rank List (map mapping )

    Water problem , It took so much time ... I don't know why , It's been compiled on this machine , But with c++ Commit but compile error ... Last use g++ Submit AC The question : give n The names of the students , Then give m It's a test . Each test gives n A student's score ...

  6. HDU 4022 Bombing (map + multiset)

    The question : stay x,y The coordinate range is 10 ^ -9 ~~ 10 ^ 9 In the coordinate axis of , Yes 10W A little bit ( Notice that some of the points may be in the same coordinates ), Then there is 10W A asked , Process queries in order of input , For each inquiry a,b    a == ...

  7. 09--STL Associate container (map/multimap)

    One :map/multimap An introduction to the map It's a standard associative container , One map Is a sequence of key value pairs , namely (key,value) Yes . It provides based on key Fast retrieval capability of . map in key Value is unique . The elements in the set are in a certain order ...

  8. (map,c_str()) Fruits hdu1263

    Fruits http://acm.hdu.edu.cn/showproblem.php?pid=1263 Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  9. Java Learning notes 24(Map aggregate )

    Map Interface : Map Interface and Collection Interface has no inheritance relationship . difference :Collection The elements in are isolated , One by one . Map As a set of maps , Each element contains Key-value Yes ( key - It's worth it ). ...

Random recommendation

  1. Use git error: RPC failed; result=22, HTTP code = 411

    Use git This error may occur when submitting larger files error: RPC failed; result=22, HTTP code = 411 fatal: The remote end hung u ...

  2. java Safe sandbox ( One ) And ClassLoader Parent delegate mechanism

    java It's a type safe language , It has four kinds of security mechanisms called safe sandbox mechanism to ensure the security of language , The four types of safety sandbox are : Class loading system .class File checker Built in Java virtual machine ( And language ) Safety features of Security manager and J ...

  3. [3D Parkour ] AudioManager

    Unity Audio Management The most common component of sound management in games is AudioSource and AudioClip, My approach is to build a AudioManager class ( Singleton class ) Manage the audio , Talk about my experience : Function list St ...

  4. To explore the requestDisallowInterceptTouchEvent The cause of the failure

    I used it yesterday requestDisallowInterceptTouchEvent When , Now it's set up requestDisallowInterceptTouchEvent(true) after , Father View Of onI ...

  5. iOS Processing of next date

    NSDate It stores universal standard time (UTC), The output needs to be converted to local time according to the time zone Dates         NSDate Class provides the ability to create date, Compare date And calculate two date The function of space between .Date The object is ...

  6. C++ Object memory model 1( stack model )

    Object memory model One . Stack (Stack) VS. Pile up (heap) Stack Automatically managed by the system , In units of executing functions The space size is determined at compile time ( Parameters + local variable ) Function execution time , The system automatically assigns a stack At the end of function execution , System establishment ...

  7. Use socket.io Build a chat room

    Studying recently nodejs, We need to find some projects to practice our hands . I found a chat room tutorial , Simple enough , You can also learn something from it . I'll take some notes during my practice . nodeJS modular It's time to 2 A module ,express and so ...

  8. Android About calling the camera installed in the system

    Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,1); The call system is installed ...

  9. java8 Actual combat II ------lambda Expressions and functional interfaces , Simple is good

    One .Lambda You can put Lambda Expressions are understood to be concise i A way to represent transitive anonymous functions : It has no name , But it has a list of parameters . Function main body . Return type , It may also be a list of exceptions that can be thrown . Sounds , Anonymous class we use , anonymous ...

  10. [ 9.22 ]CF A series of daily questions —— 484A Bits

    Description: To give you one l,r I'm going to let you find the smallest x And its binary number should contain the most 1 position , Output its decimal system Solution: I was greedy , But I'm greedy , Want to 1 Keep adding up 1, But forget 0 In the middle ...