描述

Jack and Jill have decided to sell some of their Compact Discs, while they still have some value. They have decided to sell one of each of the CD titles that they both own. How many CDs can Jack and Jill sell?

Neither Jack nor Jill owns more than one copy of each CD.

输入

The input consists of a sequence of test cases. The first line of each test case contains two non-negative integers N and M, each at most one million, specifying the number of CDs owned by Jack and by Jill, respectively. This line is followed by N lines listing the catalog numbers of the CDs owned by Jack in increasing order, and M more lines listing the catalog numbers of the CDs owned by Jill in increasing order. Each catalog number is a positive integer no greater than one billion. The input is terminated by a line containing two zeros. This last line is not a test case and should not be processed.

输出

For each test case, output a line containing one integer, the number of CDs that Jack and Jill both own.

样例输入

3 3
1
2
3
1
2
4
0 0

样例输出

2

#include<cstring>
#include<cstdio>
using namespace std;
int a[],n;
int ok(int x)
{
int bot=;
int top=n;
int mid;
while(bot<=top)
{
mid=(bot+top)/;
if(x<a[mid])
top=mid-;
else if(x>a[mid])
bot=mid+;
else
return ;
}
return ;
}
int main()
{
int m,i,x,s;
while(scanf("%d%d",&n,&m),m||n)
{
memset(a,,sizeof(a));
s=;
for(i=;i<=n;i++)
scanf("%d",&a[i]);
for(i=;i<=m;i++)
{
scanf("%d",&x);
s=s+ok(x);
}
printf("%d\n",s);
}
return ;
}

【TOJ 3369】CD(二分)的更多相关文章

  1. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  2. HDU 3763 CD【二分查找】

    解题思路:给出两个数列an,bn,求an和bn中相同元素的个数因为注意到n的取值是0到1000000,所以可以用二分查找来做,因为题目中给出的an,bn,已经是单调递增的,所以不用排序了,对于输入的每 ...

  3. TOJ 3750: 二分查找

    3750: 二分查找   Time Limit(Common/Java):3000MS/9000MS     Memory Limit:65536KByteTotal Submit: 1925     ...

  4. TOJ 6121: 学长的情书 ( 二分)

    传送门: 点我 6121: 学长的情书  时间限制(普通/Java):2000MS/6000MS     内存限制:65536KByte总提交: 79            测试通过:2 描述 抹布收 ...

  5. toj 4353 Estimation(树状数组+二分查找)

    Estimation 时间限制(普通/Java):5000MS/15000MS     运行内存限制:65536KByte总提交: 6            测试通过: 1 描述 “There are ...

  6. loj 1156(二分+最大流)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26870 思路:由于溢出问题,wa了半天,还以为构图错了呢,查了半天 ...

  7. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分

    C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...

  8. 二分查找方法和printk打印级别

    人生就是一个茶几,上面摆满了杯具.内核也是一个大茶几,不过它上面的杯具是一个个的bug.确定bug什么时候被引入是一个很关键的步骤,在这个定位bug的过程中,不论有意或无意,都会很自然地用到二分查找的 ...

  9. poj 2785 让和为0 暴力&二分

    题目链接:http://poj.org/problem?id=2785 大意是输入一个n行四列的矩阵,每一列取一个数,就是四个数,求有多少种着四个数相加和为0的情况 首先脑海里想到的第一思维必然是一个 ...

随机推荐

  1. Linux的find命令实例详解和mtime ctime atime

    这次解释一下三个Linux文件显示的三个时间,然后展示一下find命令的各个功能 在linux操作系统中,每个文件都有很多的时间参数,其中有三个比较主要,分别是ctime,atime,mtime mo ...

  2. HTML 5 表单相关元素和属性

    HTML使用表单向服务器提交请求,表单.表单控件的主要作用是收集用户输入,当用户提交表单时,用户输入内容将被作为请求参数提交到远程服务器.因此,在Web编程中,表单主要是用于收集用户输入的数据,在需要 ...

  3. 最新机动车行驶证模板PSD可编辑分层文件下载

    机动车行驶证PSD模板下载地址: http://www.qijieworld.com/thread-1834752-1-1.html 模板为psd格式,内容可编辑修改,需使用 Photoshop CS ...

  4. gsap

    TweenMax借助于css,轻量级的js库 下面是简单的demo <!DOCTYPE html> <html lang="en"> <head> ...

  5. ASP.NET MVC Tips

    1. _ViewStart.cshtml会在调用每个页面的时候执行,我们可以在页面内设置Layout页面,也可以在这个页面写一些逻辑来根据不同的情况引用不同的Layout页面,详情请参考此处:

  6. 深入浅出 关于SQL Server中的死锁问题

    深入浅出 关于SQL Server中的死锁问题 博客2013-02-12 13:44   分享到:我要吐槽 死锁的本质是一种僵持状态,是多个主体对于资源的争用而导致的.理解死锁首先需要对死锁所涉及的相 ...

  7. ORACLE_ALIAS

    Oracle / PLSQL: ALIASES website:https://www.techonthenet.com/oracle/alias.php This Oracle tutorial e ...

  8. March 24 2017 Week 12 Friday

    Our lives are brief, that is why it's important to search for meaning. 人生短暂,所以才要寻找它的意义. What can we ...

  9. selenium + python(鼠标操作)

    关于最近学习selenium自动化测试鼠标操作的一些总结 常见的鼠标操作

  10. 初次接触《C++程序设计原理与实践》一书

    前两天读书日,买了些书回来看.__Bjarne Stroustrup__的<C++程序设计原理与实践>便是其中一本.其实也没看完,只看了第0章-致读者,大师不愧是大师,只看了一章就让心生共 ...