http://codeforces.com/problemset/problem/489/B

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

解题思路: 将男孩和女孩升序排列, 分两种情况,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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #277.5 (Div. 2) ABCDF

    http://codeforces.com/contest/489 Problems     # Name     A SwapSort standard input/output 1 s, 256 ...

  5. Codeforces Round #277.5 (Div. 2)

    题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...

  6. 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 ...

  7. Codeforces Round #277.5 (Div. 2)部分题解

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. uoj#283. 直径拆除鸡(构造)

    传送门 好神的构造题 vfk巨巨的题解 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) fo ...

  2. python-selenium-robotframework安装问题

    背景 当前系统安装了两个不同版本的python,分别是python27和python36(如图1),如图 说明 系统安装的两个python版本,python2中的python.exe默认不做修改:py ...

  3. 浅谈volatile关键字

    volatile是一种轻量级的同步机制.它可以保证内存可见性以及防止指令重排序,但是不保证原子性 volatile和JMM机制是不可分割的,在谈volatile的时候有必要先了解以下JMM JMM(J ...

  4. 异常定义-Mybatis中的源码参考

    public class IbatisException extends RuntimeException { private static final long serialVersionUID = ...

  5. js监听键盘提交表单

    <!DOCTYPE html> <html> <head> <title>登陆系统</title> <link href=" ...

  6. max函数的用法

    题目是   给你一段全英文本,求这段文本中出现次数最多的字母 import string def checkio(text): text = text.lower() return max(strin ...

  7. Python -3-列表和元组

    1.用list就可以像修改列表那样修改字符串了 >>> list('Hello') ['H', 'e', 'l', 'l', 'o'] 可将任何序列作为list的参数   2.列表的 ...

  8. JAVA 操作远程mysql数据库实现单表增删改查操作

    package MysqlTest; import java.sql.DriverManager; import java.sql.ResultSet; import com.mysql.jdbc.C ...

  9. Tinghua Data Mining 2

    数据预处理 https://www.bilibili.com/video/av23933161/?p=11 http://www.xuetangx.com/courses/course-v1:Tsin ...

  10. requests发送HTTPS请求(处理SSL证书验证)

    1.SSL是什么,为什么发送HTTPS请求时需要证书验证? 1.1 SSL:安全套接字层.是为了解决HTTP协议是明文,避免传输的数据被窃取,篡改,劫持等. 1.2 TSL:Transport Lay ...