Codeforces Round #277.5 (Div. 2)-B. BerSU Ball
http://codeforces.com/problemset/problem/489/B
1 second
256 megabytes
standard input
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.
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.
Print a single number — the required maximum possible number of pairs.
4
1 4 6 2
5
5 1 5 7 9
3
4
1 2 3 4
4
10 11 12 13
0
5
1 1 1 1 1
3
1 2 3
2
解题思路: 将男孩和女孩升序排列, 分两种情况,1.当前男孩和女孩可以组成一组,那就组一组,2,当前南海比女孩的水平高1以上,查询下一个女孩,3,否则就查询下一个男孩,知道男孩或者女孩都选完
1 #include <iostream>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <time.h>
6 #include <math.h>
7
8 using namespace std;
9
int n, m, a[], b[];
int cmp(const void *a, const void *b){
return *(int *)a - *(int *)b;
}
void solve(){
int ans = , i = , j = ;
while(i < n &&j < m){
if(a[i] > b[j] + ){
j++;
}
else if(abs(a[i] - b[j]) == || a[i] == b[j]){
ans++, i++, j++;
}
else{
i++;
}
}
printf("%d\n", ans);
}
int main(){
int i;
while(scanf("%d", &n) != EOF){
for(i = ; i < n; i++){
scanf("%d", &a[i]);
}
qsort(a, n, sizeof(a[]), cmp);
scanf("%d", &m);
for(i = ; i < m; i++){
scanf("%d", &b[i]);
}
qsort(b, m, sizeof(b[]), cmp);
solve();
}
return ;
47 }
Codeforces Round #277.5 (Div. 2)-B. BerSU Ball的更多相关文章
- Codeforces Round #277.5 (Div. 2)B——BerSU Ball
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #277.5 (Div. 2) B. BerSU Ball【贪心/双指针/每两个跳舞的人可以配对,并且他们两个的绝对值只差小于等于1,求最多匹配多少对】
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #277.5 (Div. 2) ABCDF
http://codeforces.com/contest/489 Problems # Name A SwapSort standard input/output 1 s, 256 ...
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud A. SwapSort time limit per test 1 seco ...
- Codeforces Round #277.5 (Div. 2)部分题解
A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)
http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
随机推荐
- ANGULAR 使用 ng build --prod 编译报内存错误的解决办法
如果你遇到如下的情况 <--- Last few GCs ---> [13724:0000020D39C660D0] 231298 ms: Mark-sweep 1356.3 (1433. ...
- kuangbin带你飞 - 合集
[题目列表] 之前有一些做过了的,这次从数论开始?
- HDU3415【单调队列】
单调队列解决通过维护满足条件内的值,并保证队列里的值单调,解决一个最大最小. 让你求一个k区间长度的最大值,那么就只要搞下前缀和, sum[ i , j ] 区间的和:sum[ j ]-sum[ i ...
- ajax 的三种使用方法
第一种 也是最古老的一种方法之一 from 表单直接提交数据到php文件里 action为路径 <form method="post" action="./inde ...
- 点击a标签 跳到当前页面指定div
给标签div设一个id值 <div id="aa"><div> a标签抓取id值,点击跳过去 <a href="#aa">& ...
- hoj2798 Globulous Gumdrops
Globulous Gumdrops My Tags (Edit) Source : 2008 Stanford Programming Contest Time limit : 1 se ...
- 洛谷P3292 [SCOI2016]幸运数字(倍增+线性基)
传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 第一眼:这不会是个倍增LCA暴力合并线性基吧…… 打了一发……A了? 所以这真的是个暴力倍增LCA合并线性基么…… ps:据某大佬说其实可以离线之后 ...
- Android NFC 整理
Android NFC基础(多篇) http://blog.csdn.net/think_soft/article/details/8169483
- Requests 入门
首先直接通过管理员运行cmd,然后执行 pip install requests 就可以直接安装Requests库了 有个最基本的语句 r = requests.get(url) 通过request ...
- DISTINCT 去重---SQL
SQL SELECT DISTINCT 语句 在表中,一个列可能会包含多个重复值,有时您也许希望仅仅列出不同(distinct)的值. DISTINCT 关键词用于返回唯一不同的值. SQL SELE ...