1230

多重hash练习一下,不用也可以

//
// main.cpp
// codeves1230
//
// Created by Candy on 9/29/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=1e5+,MOD=,M=1e6+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int n,m,mod[]={,,},a;
bool mp[][M];
int gethash(int x,int p){
return x%mod[p];
}
int main(int argc, const char * argv[]) {
n=read();m=read();
for(int i=;i<=n;i++){
a=read();
mp[][gethash(a,)]=mp[][gethash(a,)]=mp[][gethash(a,)]=;
}
for(int i=;i<=m;i++){
a=read();
if(mp[][gethash(a,)]&&mp[][gethash(a,)]&&mp[][gethash(a,)])
printf("YES\n");
else printf("NO\n");
}
return ;
}

2875

字符串哈希,26进制

//
// main.cpp
// codevs2875
//
// Created by Candy on 9/29/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MOD=;
int n,m;
char s[],mp[MOD+];
int gethash(char s[]){
int len=strlen(s),x=;
for(int i=;i<len;i++)
x=(x*+s[i]-'a')%MOD;
return x%MOD;
}
int main(int argc, const char * argv[]) {
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s",s);
mp[gethash(s)]=;
}
scanf("%d",&m);
for(int i=;i<=m;i++){
scanf("%s",s);
if(mp[gethash(s)]) puts("Yes");
else puts("No");
}
return ;
}

最新文章

  1. 使用maven来管理java项目
  2. centos7下安装使用docker
  3. mvc3 上传图片
  4. java javacv调用摄像头并拍照
  5. SharePoint 2013 开发——搜索架构及扩展
  6. [转载] 理解RESTful架构
  7. 用Javascript弹出div定义的消息框并往块里面填写文字
  8. Map:比较新增加日期的和需要删除的日期 使用方法
  9. 李洪强iOS开发之OC语言@property @synthesize和id
  10. .net中下载文件的方法(转)
  11. HDU 1294 Rooted Trees Problem
  12. poj 2503 Babelfish(Map、Hash、字典树)
  13. 使用WCF扩展记录服务调用时间
  14. EffectiveC++ 第7章 模板与泛型编程
  15. ecplise 正则替换技巧
  16. 乐观锁与悲观锁以及乐观锁的一种实现方式-CAS
  17. View.requestLayout
  18. Beta阶段冲刺2.0
  19. MySql习题和答案
  20. lvm创建和快照

热门文章

  1. jQuery构造函数init参数分析(二)
  2. 为Sharepoint 2010 批量创建SharePoint测试用户
  3. Linux学习心得之 LVM管理与Linux系统安装
  4. Swift开发第十二篇——protocol组合&amp;static和class
  5. 一个统计报表sql问题
  6. (转) 一步一步学习ASP.NET 5 (五)- TypeScript
  7. (转) 一步一步学习ASP.NET 5 (三)- 认识新的Web结构
  8. jsp学习笔记一
  9. Git从零开始怎么学?
  10. SQL Server连接SQL Server、SQL Server连接ORACLE 链接服务器