hdu 3763 CD(二分)
来源:互联网 发布:易推微博助手软件 编辑:程序博客网 时间:2024/05/16 13:07
CD
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 630 Accepted Submission(s): 282
Problem Description
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.
Neither Jack nor Jill owns more than one copy of each CD.
Input
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.
Output
For each test case, output a line containing one integer, the number of CDs that Jack and Jill both own.
Sample Input
3 31231240 0
Sample Output
2
#include<stdio.h>#include<istream>#include<algorithm>using namespace std;int s[10000005];int fun(int x,int n){int mid,low,high;low=1;high=n;mid=(low+high)/2;while(low<=high){mid=(low+high)/2;if(x<s[mid])high=mid-1;else if(x>s[mid])low=mid+1;else return 1;}return 0;}int main(){int m,n,i,j,a;int sum;while(scanf("%d%d",&n,&m),n+m){sum=0;for(i=1;i<=n;i++){scanf("%d",&s[i]);}for(j=1;j<=m;j++){scanf("%d",&a);sum+=fun(a,n);}printf("%d\n",sum);}return 0;}
0 0
- hdu 3763 CD(二分)
- hdu 3763 CD(二分)
- hdu 3763 CD(二分查找)
- HDU 3763 CD(二分查找)
- hdu 3763 CD(二分查找)
- HDU 3763 CD
- hdu 3763 CD
- HDU 3763-CD
- CD(二分)
- hdoj 3763 CD(二分查找)
- HDU3763 CD 二分
- hdu 3763 二分
- HDU3763.CD——二分
- HDU 3736 CD
- hdu 4547 CD操作
- hdu 4547 CD操作
- CD操作 HDU
- HDU 4547 CD操作 LCA
- Linux安装程序Anaconda分析
- 生成不重复随机数
- listView用法
- Servlet生命周期与工作原理
- Android应用开发性能优化系列总篇
- hdu 3763 CD(二分)
- SqlServer关于select into 和 insert into select 两种表复制语句
- JAVA8 十大新特性详解
- 多项式加法
- kbe定时器框架
- 【数据结构第二周】堆栈知识点整理
- Android 插件化 动态升级
- ADO与ADO.NET区分
- 同余定理