MapReduce API基本概念 序列化,Reporter参数,回调机制 ---《hadoop技术内幕》读书笔记
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MapReduce API基本概念 序列化,Reporter参数,回调机制 ---《hadoop技术内幕》读书笔记,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4433字,纯文字阅读大概需要7分钟。
内容图文
Crazy Search
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1611 Accepted Submission(s): 586
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 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.
1 3 4 daababac
5
#include<algorithm> #include<iostream> #include<string.h> #include<sstream> #include<stdio.h> #include<math.h> #include<vector> #include<string> #include<queue> #include<set> #include<map>//常用的头文件。不知道有什么用的可以百度。 //#pragma comment(linker,"/STACK:1024000000,1024000000") using namespace std; const int INF=0x3f3f3f3f; const double eps=1e-8; const double PI=acos(-1.0); const int maxn=16000010; typedef __int64 ll; char txt[maxn],tp; map<string,int> mp;//建立map映射 int main() { int i,j,n,nc,t,len,ans,one=1; scanf("%d",&t); while(t--) { if(!one)//判断是否是第一个输入。因为样例之间要空一行。 printf("\n"); scanf("%d%d",&n,&nc); scanf("%s",txt); len=strlen(txt); ans=0; mp.clear();//全部清0 for(j=n;j<=len;j++) { tp=txt[j]; txt[j]=‘\0‘; string tt(txt+j-n);//取出字符串.其实可以string tt(txt+j-n,n)。比赛时忘了 txt[j]=tp; if(!mp[tt]) ans++,mp[tt]=1; } printf("%d\n",ans); one=0; } return 0; }
#include<algorithm> #include<iostream> #include<string.h> #include<sstream> #include<stdio.h> #include<math.h> #include<vector> #include<string> #include<queue> #include<set> #include<map>//常用的头文件。不知道有什么用的可以百度。 //#pragma comment(linker,"/STACK:1024000000,1024000000") using namespace std; const int INF=0x3f3f3f3f; const double eps=1e-8; const double PI=acos(-1.0); const int maxn=16000010; const int maxm=8000007; const int mod=1000007; typedef __int64 ll; char txt[maxn],tp; int nc; int Hash[maxm],id[28]; int getkey(int st,int len)//获取hash值 { int i,key=0; for(i=0;i<len;i++) key=key*nc+id[txt[st+i]-‘a‘]; return key; } int main() { int i,n,t,tp,len,ans,key,cnt; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&nc); scanf("%s",txt); memset(Hash,0,sizeof Hash); memset(id,-1,sizeof id); ans=cnt=0; len=strlen(txt); for(i=0;i<len;i++) { tp=txt[i]-‘a‘; if(id[tp]==-1) id[tp]=cnt++;//压缩字母的数值 if(cnt==nc) break; } for(i=n;i<=len;i++) { key=getkey(i-n,n); key%=maxn; if(!Hash[key]) ans++,Hash[key]=1; } printf("%d\n",ans); if(t)//判断是否是第一个输入。因为样例之间要空一行。 printf("\n"); } return 0; }
比较两种做法。更喜欢第一种。简单快捷。最重要的准确性高。第二种方法数据大了完全就不行!但是这也是一种思路。a=所谓hash如果你的hash函数好。冲突率很小的话。也不妨一试。
原文:http://blog.csdn.net/smile0198/article/details/20954395
内容总结
以上是互联网集市为您收集整理的MapReduce API基本概念 序列化,Reporter参数,回调机制 ---《hadoop技术内幕》读书笔记全部内容,希望文章能够帮你解决MapReduce API基本概念 序列化,Reporter参数,回调机制 ---《hadoop技术内幕》读书笔记所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。