(以“分类:哈希表 ==摘要== {{信息题|统计单词个数|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了(当然排序完二分也行)。
+
*钻石第一题,理论上是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代码已折叠

2015年2月3日 (二) 18:21的最后版本

摘要

题目链接 难度等级 完成状态 完成分数 最后编辑时间 需要注意
统计单词个数 ★☆☆☆☆ 答案正确 100 2015-2-3 18:10:47

题意

n个数的数集A,m个查询:数是否属于A;

题解

  • 钻石第一题,理论上是hash裸题,但是懒……就STL了(当然排序完二分也行)。但是其实这数据量bitset/bool数组也行。

附赠bitset用法:

显示/移除行号
  1. #include<bitset> //库//
  2. bitset<100000000> a; //声明//
  3. a[1232132]=true;//使用//
  4. a.flip();//全部翻转//
  5. a.set();//全部设true//
  6. a.reset();//全部设false//
  7. a.count();//1的个数//

代码

1230.cpp代码已折叠
展开折叠内容
显示/移除行号
  1. #include<iostream>
  2. #include<set>
  3. #include<cstdio>
  4. using namespace std;
  5. set<int> s;
  6. int n,m;
  7. int main()
  8. {
  9. scanf("%d%d",&n,&m);
  10. for(int i=1,a;i<=n;++i)
  11. scanf("%d",&a),
  12. s.insert(a);
  13. for(int i=1,a;i<=m;++i)
  14. scanf("%d",&a),
  15. printf(s.count(a)?"YES\n":"NO\n");
  16. return 0;
  17. }

著作权声明[编辑]

关于[编辑]