【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的情况 首先脑海里想到的第一思维必然是一个 ...
随机推荐
- 【Spring Boot】集成Netty Socket.IO通讯框架
服务端 @Configuration public class NettySocketConfig { private static final Logger logger = LoggerFacto ...
- rest-framework框架——APIView和序列化组件
一.快速实例 Quickstart http://www.cnblogs.com/yuanchenqi/articles/8719520.html restful协议 ---- 一切皆是资源,操作只是 ...
- Dubbo架构原理
1 Dubbo核心功能 Remoting:远程通讯,提供对多种NIO框架抽象封装,包括“同步转异步”和“请求-响应”模式的信息交换方式. Cluster: 服务框架,提供基于接口方法的透明远程过程调用 ...
- linux下查看磁盘分区的文件系统格式
df -T 只可以查看已经挂载的分区和文件系统类型. Filesystem Type 1K-blocks Used Available Use% Mounted on/dev/sda1 ext4 20 ...
- SVN学习——简单入门之创建仓库、导入、检出(一)
从刚刚参加工作就开始使用svn,清晰的记得那年师姐比较生气的来找我:“你怎么又不更新就提交代码了,把我写的都给覆盖掉了”,哈哈~ 虽然一直在用svn,不过在日常工作中主要用到的是简单的操作,而且大多数 ...
- [C#] SHA1校验函数用法
首先引用这个命名空间 using System.Security.Cryptography; //建立SHA1对象 SHA1 sha = new SHA1CryptoServiceProvider() ...
- SQL 创建自定义方法,匹配正则
C#代码 using System.Text.RegularExpressions; public class FunctionRegex { [Microsoft.SqlServer.Server. ...
- React学习笔记 - JSX简介
React Learn Note 2 React学习笔记(二) 标签(空格分隔): React JavaScript 一.JSX简介 像const element = <h1>Hello ...
- Do the Untwist
Do the Untwist Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- sql相同记录取时间最大的信息