【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 ;
}
【TOJ 3369】CD(二分)的更多相关文章
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- HDU 3763 CD【二分查找】
解题思路:给出两个数列an,bn,求an和bn中相同元素的个数因为注意到n的取值是0到1000000,所以可以用二分查找来做,因为题目中给出的an,bn,已经是单调递增的,所以不用排序了,对于输入的每 ...
- TOJ 3750: 二分查找
3750: 二分查找 Time Limit(Common/Java):3000MS/9000MS Memory Limit:65536KByteTotal Submit: 1925 ...
- TOJ 6121: 学长的情书 ( 二分)
传送门: 点我 6121: 学长的情书 时间限制(普通/Java):2000MS/6000MS 内存限制:65536KByte总提交: 79 测试通过:2 描述 抹布收 ...
- toj 4353 Estimation(树状数组+二分查找)
Estimation 时间限制(普通/Java):5000MS/15000MS 运行内存限制:65536KByte总提交: 6 测试通过: 1 描述 “There are ...
- loj 1156(二分+最大流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26870 思路:由于溢出问题,wa了半天,还以为构图错了呢,查了半天 ...
- 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 ...
- 二分查找方法和printk打印级别
人生就是一个茶几,上面摆满了杯具.内核也是一个大茶几,不过它上面的杯具是一个个的bug.确定bug什么时候被引入是一个很关键的步骤,在这个定位bug的过程中,不论有意或无意,都会很自然地用到二分查找的 ...
- poj 2785 让和为0 暴力&二分
题目链接:http://poj.org/problem?id=2785 大意是输入一个n行四列的矩阵,每一列取一个数,就是四个数,求有多少种着四个数相加和为0的情况 首先脑海里想到的第一思维必然是一个 ...
随机推荐
- Java ConcurrentHashMap的小测试
今天正式开始自己的分布式学习,在第一章介绍多线程工作模式时,作者抛出了一段关于ConcurrentHashMap代码让我很是疑惑,代码如下: public class TestClass { priv ...
- select, poll, epoll笔记
看网络通信框架,netty, thrift,java nio等,最后都会通过select, poll, epoll或者socket等进行通信.查了些网页,总结一下.做个笔记 1. Socket单线程阻 ...
- Spring课程 Spring入门篇 4-5 Spring bean装配之基于java的容器注解说明--@Bean
1 解析 2.1 @bean注解定义 2.2 @bean注解的使用 2 代码演练 2.1 @bean的应用不带name 2.2 @bean的应用带name 2.3 @bean注解调用initMet ...
- linux定时任务crontab的使用
crond进程: crond是linux下用来周期性地执行某种任务的一个守护进程,安装操作系统默认会安装此服务工具,并且会自动启动crond进程. 设置定时任务过程: 1. 创建任务文件(.sh) [ ...
- Django的MTV模式详解
参考博客:https://www.cnblogs.com/yuanchenqi/articles/7629939.html 一.MVC模型 Web服务器开发领域里著名的MVC模式. 所谓MVC就是把W ...
- select @@identity用法
用select @@identity得到上一次插入记录时自动产生的ID 如果你使用存储过程的话,将非常简单,代码如下:SET @NewID=@@IDENTITY 说明: 在一条 INSERT.SELE ...
- 《ArcGIS Runtime SDK for Android开发笔记》——问题集:如何解决ArcGIS Runtime SDK for Android中文标注无法显示的问题(转载)
Geodatabase中中文标注编码乱码一直是一个比较头疼的问题之前也不知道问题出在哪里?在百度后发现园子里的zssai已经对这个问题原因做了一个详细说明.这里将原文引用如下: 说明:此文转载自htt ...
- wxGridCellEditor
wxGridCellEditor Class Referenceabstract Class List by Category » Grid Related Classes #include < ...
- mac 上配置 maven
1. 将maven压缩包解压至/Users/suqiuhui/Applications目录下的新建文件夹dev下 2. 打开终端(系统根目录,~/下) 3. 如果没有 .bash_profile 文件 ...
- BSTR和CComBSTR使用指南
msdn关于bstr的分配和释放的注意事项:http://msdn.microsoft.com/zh-cn/library/cc485262(VS.71).aspx msdn对 CComBSTR 的使 ...