(以“分类:哈希表 ==摘要== {{信息题|统计单词个数|http://www.codevs.cn/problem/1230/|1|100|time=2015-2-3 18:10:47}} ==题意== n个数的数集A,m个...”为内容创建页面) |
小 (→题解: bitset) |
||
| 第5行: | 第5行: | ||
n个数的数集A,m个查询:数是否属于A; | n个数的数集A,m个查询:数是否属于A; | ||
==题解== | ==题解== | ||
| − | * | + | *钻石第一题,理论上是hash裸题,但是懒……就STL了(当然排序完二分也行)。但是其实这数据量bitset/bool数组也行。 |
| + | 附赠bitset用法: | ||
| + | #include<bitset> //库// | ||
| + | bitset<100000000> a; //声明// | ||
| + | a[1232132]=true;//使用// | ||
| + | a.flip();//全部翻转// | ||
| + | a.set();//全部设true// | ||
| + | a.reset();//全部设false// | ||
| + | a.count();//1的个数// | ||
| + | |||
==代码== | ==代码== | ||
{{折叠|1230.cpp代码已折叠 | {{折叠|1230.cpp代码已折叠 | ||
| 题目链接 | 难度等级 | 完成状态 | 完成分数 | 最后编辑时间 | 需要注意 |
|---|---|---|---|---|---|
| 统计单词个数 | ★☆☆☆☆ | 答案正确 | 100 | 2015-2-3 18:10:47 | 无 |
n个数的数集A,m个查询:数是否属于A;
附赠bitset用法:
#include<bitset> //库// bitset<100000000> a; //声明// a[1232132]=true;//使用// a.flip();//全部翻转// a.set();//全部设true// a.reset();//全部设false// a.count();//1的个数//
| 1230.cpp代码已折叠
展开折叠内容
|
|---|
#include<iostream>
#include<set>
#include<cstdio>
using namespace std;
set<int> s;
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1,a;i<=n;++i)
scanf("%d",&a),
s.insert(a);
for(int i=1,a;i<=m;++i)
scanf("%d",&a),
printf(s.count(a)?"YES\n":"NO\n");
return 0;
}
|