【BestCoder】36 B Gunner(哈希)
来源:互联网 发布:男双肩包推荐 知乎 编辑:程序博客网 时间:2024/06/05 05:00
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define MAX 1000010#define mod 1000007int head[MAX],cnt;struct edge{ int x; int cnt; int next;}edg[MAX];void add(int x){ int mid = x%mod; for (int i = head[mid]; i != -1; i = edg[i].next) { if (x == edg[i].x) { edg[i].cnt++; return; } } edg[cnt].x = x; edg[cnt].next = head[mid]; edg[cnt].cnt = 1; head[mid] = cnt++;}int Scan()//读入外挂{ int res = 0, ch, flag = 0; if ((ch = getchar()) == '-') //判断正负 flag = 1; else if (ch >= '0' && ch <= '9') //得到完整的数 res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0'; return flag ? -res : res;}int getb(int x){ int mid = x%mod; for (int i = head[mid]; i != -1; i = edg[i].next) { if (x == edg[i].x) { int v=edg[i].cnt; edg[i].cnt = 0; return v; } } return 0;}int main(){ int n, k; while (~scanf("%d%d", &n, &k)) { int x; cnt = 0; memset(head, -1, sizeof(head)); while (n--) { x = Scan(); add(x); } while (k--) { x = Scan(); printf("%d\n", getb(x)); } }}
0 0
- 【BestCoder】36 B Gunner(哈希)
- BestCoder Round #36(Gunner-hash)
- BestCoder Round #36 HDU 5199 Gunner
- 【BestCoder】HDU 5199 Gunner
- HDU 5199/BC 36B Gunner
- 【BestCoder】 HDOJ 5233 Gunner II
- 【CUGBACM15级BC第36场 B】hdu 5199 Gunner
- HDU5233 Gunner II && BestCoder Round #42
- hdu 5233- Gunner II(BestCoder Round #42)离散化
- Fibonacci (BestCoder Round #28 B)
- BestCoder Round #41 -- (A,B)
- hdu5340&Bestcoder(#49)b题
- BestCoder Round #80(B)高精度
- hdu 5199 Gunner(hash)
- bestcoder 20 A,B
- BestCoder Round #20 B
- BestCoder #74 B (div2)
- Bestcoder #80 B
- Android系统的进程分类
- SSH框架实现MYSQL数据库备份与还原
- web项目--BBS之从数据库查询动态生成版块信息问题分析和小结
- 使用Jquery解析Json基础知识
- Hibernate基础
- 【BestCoder】36 B Gunner(哈希)
- android开发 - Application类
- C++ Primer Plus第六版编程练习9.4解答
- 求最大子数组和
- Linux协议栈-netfilter(5)-iptables
- 设计模式之--Facade模式
- 【SeedCoder 2015年热身】写在最前面的话
- C语言 编写一个函数,传入a,b两个int类型的变量,返回两个值的最大公约数。
- Islands Travel——SPFA求最短路