http://wikioi.com/problem/1230/ 这题我真的不好意思写题解了...set练手.. #include <cstdio> #include <set> using namespace std; int main() { int n, m, t; scanf("%d%d", &n, &m); set<int> s; for(int i=1; i<=n; ++i) scanf("%d",…
题目连接:http://codevs.cn/problem/1230/ 说白了就是要我们自己手写一个哈希表的数据结构来实现加入和查找功能.map也能直接过(我第一次写就是用map骗AC的) 提一下个人理解的哈希表的实现(以下说的是线性寻址法).假设有误还请各位大神不吝不吝赐教 用一个数组模拟哈希表,函数f(x)=数字x在哈希表中出现的下标的最小可能值.一般f(x)=x mod t,t就是哈希表的长度 以下就是一个哈希表的演示样例,假设遍历哈希表时指针走出了哈希表的终点.就进入起点又一次遍历 对于…
http://www.lydsy.com/JudgeOnline/problem.php?id=2761 太水了,不说了. 但是这格式错误我已经没话说了....行末不能有空格 #include <cstdio> #include <set> using namespace std; set<int> s; int main() { int t, n, r, i; scanf("%d", &t); while(t--) { scanf(&quo…
题目链接:http://codevs.cn/problem/1230/ 题解: 会有很多方法写这道题,写个裸的哈希练练手 #include<cstdio> ,MOD=; int n,m,head[MAXN/MOD],cnt; struct edge { int v,next; }e[MAXN/]; int hash(int x) { return x%MOD; } void add(int x,int y) { e[++cnt]=(edge){y,head[x]}; head[x]=cnt;…
1.题目戳这里 2.代码: #include<iostream> #include<algorithm> using namespace std; int n,m,a[100001],num; //二分法 void search(int x) { int l,r=n; while(l<=r) { int mid=(l+r)/2; if(x>a[mid]) { l=mid+1; } else { r=mid-1; } } if(a[l]==x) { cout<<…
#include <iostream> #include <cstdio> #include <cmath> using namespace std; const int maxN = 100005; int a[maxN]; int t, tt; int n, q, x, y; int Bsearch_lower_bound(int x) { int l = 0, r = n - 1, mid = 0; while (l <= r) { mid = (l + r…
时间限制: 1 s 空间限制: 128000 Ks 题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过. 输入描述 Input Description 第一行两个整数 n 和m. 第二行n个正整数(1<=n<= 100000) 第三行m个整数(1<=m<=100000) 输出描述 Output Description 一共m行,若出现则输出YES,否…
1230 元素查找  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过. 输入描述 Input Description 第一行两个整数 n 和m. 第二行n个正整数(1<=n<= 100000) 第三行m个整数(1<=m<=100000) 输出描述 Output Description 一共m…
1230 元素查找  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过. 输入描述 Input Description 第一行两个整数 n 和m. 第二行n个正整数(1<=n<= 100000) 第三行m个整数(1<=m<=100000) 输出描述 Output Description 一共m行,若出现则…
1230 元素查找  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description 给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过. 输入描述 Input Description 第一行两个整数 n 和m. 第二行n个正整数(1<=n<= 100000) 第三行m个整数(1<=m<=100000) 输出描述 Output Description 一共m行,若出现则输出YES…