【TOJ 3369】CD(二分)
描述
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 ;
}
最新文章
- Entity Framework 6 Recipes 2nd Edition(13-2)译 ->; 用实体键获取一个单独的实体
- python爬虫学习(7) —— 爬取你的AC代码
- opencv单目摄像机标定(一)
- php 数据访问(以mysql数据库为例)
- 使用substring和split方法从字符串中抽取一组清单
- [转] Windows下使用Python读取Excel表格数据
- hadoop2.2编程: SequenceFileWritDemo
- Android手势操作
- ScrollView嵌套listview 时根据内容动态设置listview高度
- linux mysql密码破解一张图解释
- Django Web开发【3】创建网络收藏夹
- Cenots安装openvpn、pam_mysql进行用户认证和流量控制
- 剑指offer——矩阵覆盖(斐波那契变形)
- 百度AI开放平台- API实战调用
- MySQL常用配置参数
- Java集合中的LinkedHashMap类
- CentOS 远程桌面相关服务安装笔记
- Golang 知识点总结
- python3+selenium入门13-操作cookie
- Django 框架 Form组件