博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 489B BerSU Ball (水题 双指针)
阅读量:5307 次
发布时间:2019-06-14

本文共 1816 字,大约阅读时间需要 6 分钟。

B. BerSU Ball
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.

We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.

For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill.

Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.

Output

Print a single number — the required maximum possible number of pairs.

Sample test(s)
input
4 1 4 6 2 5 5 1 5 7 9
output
3
input
4 1 2 3 4 4 10 11 12 13
output
0
input
5 1 1 1 1 1 3 1 2 3
output
2 水题 双指针模拟一下就行了,用i和j分别指向两个数组,如果a[i]和b[j]相差小于等于1的话,就ans++ i++ j++,否则就较小那边向前移动一下
#include 
#include
#include
#include
using namespace std;typedef long long ll;typedef pair
pii;const int INF = 1e9;const double eps = 1e-6;const int N = 110;int cas = 1;int a[N],b[N];int n,m;bool ok(int x,int y){ return x-y>=-1 && x-y<=1;}void run(){ for(int i=0;i

 

转载于:https://www.cnblogs.com/someblue/p/4109668.html

你可能感兴趣的文章
创新课程管理系统数据库设计心得
查看>>
Hallo wolrd!
查看>>
16下学期进度条2
查看>>
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
Chapter 3 Phenomenon——12
查看>>
C语言中求最大最小值的库函数
查看>>
和小哥哥一起刷洛谷(1)
查看>>
jquery对id中含有特殊字符的转义处理
查看>>
遇麻烦,Win7+Ubuntu12.10+Archlinux12.10 +grub
查看>>
SqlBulkCopy大批量导入数据
查看>>
pandas 修改指定列中所有内容
查看>>
「 Luogu P2285 」打鼹鼠
查看>>
lua语言入门之Sublime Text设置lua的Build System
查看>>
vue.js基础
查看>>
电脑的自带图标的显示
查看>>
[转载] redis 的两种持久化方式及原理
查看>>
C++ 删除字符串的两种实现方式
查看>>
ORA-01502: 索引'P_ABCD.PK_WEB_BASE'或这类索引的分区处于不可用状态
查看>>
Java抽象类和接口的比较
查看>>
开发进度一
查看>>