HDU 3763 C D(二分)
来源:互联网 发布:上海网络推广 编辑:程序博客网 时间:2024/06/10 20:42
C D
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1090 Accepted Submission(s): 480
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.
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 Input3 31231240 0Sample Output2SourceUniversity of Waterloo Local Contest 2010.09.26
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;int a[1000010];int n,m,t;int fin(int p){ int left=0,right=n-1,mid; while(left<=right) { mid=(left+right)/2; if(a[mid]==p) return 1; else if(a[mid]>p) { right=mid-1; } else left=mid+1; } return 0;}int main(){ int k; while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; for(int i=0;i<n;i++) scanf("%d",&a[i]); k=0; while(m--) { scanf("%d",&t); if(fin(t)==1) k++; } printf("%d\n",k); } return 0;}
- HDU 3763 C D(二分)
- HDU-4190 Problem D【二分答案】
- HDU 5726-D-GCD- RMQ+二分
- 【2016-CCPC-C】二分,动脑筋(Car,hdu 5935)
- HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)
- hdu 3763 CD(二分查找)
- hdu 3763 二分
- hdu 3763 CD(二分)
- hdu 3763 CD(二分)
- hdu 2503 a/b + c/d(水)
- 杭电(hdu)ACM 2503 a/b + c/d
- HDU 2503 a/b + c/d(水~)
- HDU 2503 a/b + c/d(GCD)
- hdu 2503 a/b+c/d(基础数论)
- HDU 2503 a/b + c/d(gcd问题)
- hdu 2141(二分)
- hdu 1895(二分)
- hdu 1551(二分)
- Android 如何使用小的Ratingbar
- Linux基础
- 使用Python3计算HTTP的摘要Response值
- 随机函数的应用
- 单调队列学习笔记
- HDU 3763 C D(二分)
- Java学习——面向对象基础
- java设计模式-单例模式
- python pygame练习
- PAT乙级1063
- 11. Container With Most Water
- 编程求和:s=a+aa+aaa+aaaa+ ??+aaaa?aaa(n个),其中a为1~9中的一个数字。 提示:若第一项为a , 以后每一项由前一项乘以10加上a递推得到,然后求和。 #incl
- 21.post与get的区别
- 算法:动态申请数组(new)后将数组所有元素置零(初始化数组)的方法(炒鸡简单)(C++语言)