set(二叉搜索树)
找球号(一)
- 描述
- 在某一国度里流行着一种游戏。游戏规则为:在一堆球中,每个球上都有一个整数编号i(0<=i<=100000000),编号可重复,现在说一个随机整数k(0<=k<=100000100),判断编号为k的球是否在这堆球中(存在为"YES",否则为"NO"),先答出者为胜。现在有一个人想玩玩这个游戏,但他又很懒。他希望你能帮助他取得胜利。
- 输入
- 第一行有两个整数m,n(0<=n<=100000,0<=m<=1000000);m表示这堆球里有m个球,n表示这个游戏进行n次。
 接下来输入m+n个整数,前m个分别表示这m个球的编号i,后n个分别表示每次游戏中的随机整数k
- 输出
- 输出"YES"或"NO"
- 样例输入
- 
6 4 
 23 34 46 768 343 343
 2 4 23 343
- 样例输出
- 
NO 
 NO
 YES
 YES#include <iostream> 
 #include <algorithm>
 #include <cstdio>
 #include <queue>
 #include <set>
 using namespace std;
 int main()
 {
 set<int> p;
 int x,y,i,j,q;
 while(~scanf("%d%d",&x,&y)
 {
 for(i=;i<x;i++)
 {
 scanf("%d",&j);
 p.insert(j);
 }
 for(i=;i<y;i++)
 {
 scanf("%d",&j);
 if(p.find(j)==p.end())
 cout<<"NO"<<endl;
 else
 cout<<"YES"<<endl;
 }
 }
 }
set(二叉搜索树)的更多相关文章
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
		二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ... 
- [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化
		Serialization is the process of converting a data structure or object into a sequence of bits so tha ... 
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
		Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ... 
- [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点
		Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ... 
- [LeetCode] Binary Search Tree Iterator 二叉搜索树迭代器
		Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ... 
- [LeetCode]  Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树
		Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ... 
- [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树
		Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这道 ... 
- [LeetCode] Recover Binary Search Tree 复原二叉搜索树
		Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ... 
- [LeetCode] Validate Binary Search Tree 验证二叉搜索树
		Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ... 
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
		Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ... 
随机推荐
- Intel 凌动 D525 产品参数Intel 凌动 Z3735F 产品参数
			https://item.taobao.com/item.htm?spm=a230r.1.14.8.kauehT&id=40450541158&ns=1&abbucket=19 ... 
- unix c 01
			gcc编译器(代码的 预处理/汇编/编译/连接) C程序员一般写程序会定义 .c和.h两种文件 .c文件(源文件)中一般放代码的实现,.h文件(头文件)中放 各种声明和定义. gcc -E __. ... 
- SQL Interview Question
			面试的时候发现会问一些SQL的基本问题,在此总结一下. ProgramInterview/SQL 这个网站上的问题还比较全. 1. Join type INNER JOIN: Returns all ... 
- 【POJ3299】Humidex(简单的数学推导)
			公式题中已经给出,直接求解即可. #include <iostream> #include <cstdlib> #include <cstdio> #include ... 
- 基于微信公众平台的开发(清华大学第二讲)_Alien的笔记
			基于微信公众平台的开发(清华大学第二讲)_Alien的笔记 基于微信公众平台的开发(清华大学第二讲) 
- zedboard--Opencv移植和zedboard测试(十一)
			继上次生成了ARM架构的链接库之后,我们要把他们拷贝到装载有文件系统的SD卡中即可,在拷贝时,最好是/usr/lib下 实践一:将那些lib拷贝到U盘里面,因为之前跑过demo,里面就是一个简易的li ... 
- C#模拟网站用户登录
			我们在写灌水机器人.抓资源机器人和Web网游辅助工具的时候第一步要实现的就是用户登录.那么怎么用C#来模拟一个用户的登录拉?要实现用户的登录,那么首先就必须要了解一般网站中是怎么判断用户是否登录的. ... 
- [core java学习笔记][第四章对象与类]
			4.3 用户自定义类 4.3.1 类数组的声明 需要两次new Employee[]=staff=new Employedd[3]; staff[0]=new Employedd(参数列表); sta ... 
- jquery css3 手机菜单动画综合版
			html <header> <a id="go-back" href="javascript:window.location.back(-1)" ... 
- 如何用浏览器调试js代码
			按F12打开调试工具 
