poj 1200:Crazy Search (Hash)
来源:互联网 发布:50而知天命什么意思 编辑:程序博客网 时间:2024/05/18 02:43
1200:Crazy Search
- 查看
- 提交
- 统计
- 提示
- 提问
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
- 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. - 输入
- 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.
- 输出
- The program should output just an integer corresponding to the number of different substrings of size N found in the given text.
- 样例输入
3 4daababac
- 样例输出
5
- 提示
- Huge input,scanf is recommended.
- 来源
- Southwestern Europe 2002
#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<iomanip>#include<queue>#include<stack>#include<vector>#include<set>#include<map>using namespace std;int n,nc,num=0,ans=0; string s;bool Vis[1005];int V[1005];bool Hash[16000005];int main(){cin>>n>>nc;cin>>s;int len=s.length();for(int i=0;i<len;++i) {if(!Vis[s[i]]){Vis[s[i]]=true;V[s[i]]=++num;}}for(int i=0;i<=len-n;++i){int sum=0; for(int j=i;j<i+n;++j){sum+=nc*sum+V[s[j]];} if(!Hash[sum]){ans++;Hash[sum]=true;}}cout<<ans<<endl;return 0;}
阅读全文
0 0
- POJ 1200 Crazy Search //HASH
- poj 1200 Crazy Search【hash】
- POJ 1200 Crazy Search(Hash)
- POJ 1200 Crazy Search(hash).
- [POJ] 1200 Crazy Search [HASH]
- poj 1200:Crazy Search (Hash)
- hash POJ 1200 Crazy Search
- POJ 1200 Crazy Search hash水题
- poj 1200 Crazy Search 字符串hash
- POJ 1200 Crazy Search(HASH)
- POJ 1200 Crazy Search (字符串hash)
- poj 1200 Crazy Search(字符串hash)
- POJ 1200 Crazy Search hash入门
- poj 1200 || zoj 1507 Crazy Search (Hash表)
- POJ题目1200 Crazy Search(字符串hash)
- hash&Rabin-Karp字符串查找POJ 1200 Crazy Search
- POJ-1200 Crazy Search,人生第一道hash题!
- POJ 1200 Crazy Search
- 利用机器学习算法进行特朗普twitter的主题分析
- 【ExtJS】Web项目引入ExtJS
- SpringBoot22-spingboot数据访问-Spring Data JPA
- LeetCode——倒序輸出
- 如何使用Python基于Pygame写一个简易的微信打飞机游戏。
- poj 1200:Crazy Search (Hash)
- 【学习笔记十】- 使用<canvas>绘图 《js高程》15 笔记
- 【20171002】python_语言设计(4)文件
- ArcGIS for Android Runtime100 基本操作(一)——点线面测距离长度和面积
- 清 · 北 ·Ⅰ
- hdu 5044(树链剖分+区间标记小优化)
- 身份证号信息查询工具
- 使用jreloader实现tomcat中class文件的热部署
- java深入学习十二之文件