zoukankan      html  css  js  c++  java
  • hdu 1381 Crazy Search(hash/map的应用)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1381

    Crazy Search

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 1178    Accepted Submission(s): 459

    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
     
    分析:这里的NC没什么用,NC嘛,当然没什么用咯,你说脑残会有什么用呢  呵呵
             这题 主要任务就是 判断重复 的字符串   这里我们用到map  因为map可以自动覆盖相同的key
     
     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<math.h>
     4 #include<algorithm>
     5 #include<string.h>
     6 #include<string>
     7 #include<ctime>
     8 #include<queue>
     9 #include<list>
    10 #include<map>
    11 #define INF 9999999
    12 #define MAXN 10000
    13 using namespace std;
    14 //    priority_queue<int,vector<int>,greater<int> > pq;
    15 
    16 int main()
    17 {
    18     int T,N,NC,i;
    19     string text;
    20     map<string,int> Stat;
    21     cin>>T;
    22     while(T--)
    23     {
    24         cin>>N>>NC>>text;
    25         Stat.clear();
    26         const int Size = text.size();
    27         for(i=0;i<Size-N+1;++i)
    28         {
    29             string tmp(text,i,N);  //string类的构造函数,很强大吧
    30             Stat[tmp]=i;   //加入map之后 自动会对重复的key进行覆盖
    31         }
    32         cout<<Stat.size()<<endl;
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    Shell笔记——文本操作
    Shell笔记——加密命令
    conda,pip 安装指定版本的指定包
    如何检查tensorflow环境是否能正常调用GPU
    Windows10中使用Anaconda安装keras-gpu版本(遇到的坑)
    canvas一些属性
    块级元素,行内元素,行内块级元素都有哪些
    面向对象版Tab栏切换
    注册事件的兼容性处理
    常见的移动端问题
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3001075.html
Copyright © 2011-2022 走看看