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. bzoj 2395: [Balkan 2011]Timeismoney【计算几何+最小生成树】

    妙啊,是一个逼近(?)的做法 把两个值最为平面上的点坐标,然后答案也是一个点. 首先求出可能是答案的点xy分别是按照c和t排序做最小生成树的答案,然后考虑比这两个点的答案小的答案,一定在xy连线靠近原 ...

  2. Mol Cell Proteomics. |王欣然| 基于微粒的蛋白聚合物捕获技术让能满足多种不同需求的蛋白质组学样品制备方法成为可能

    大家好,本周分享的是发表在Molecular & Cellular Proteomics. 上的一篇关于蛋白质组学样本质谱分析前处理方法改进的文章,题目是Protein aggregation ...

  3. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:5. 设置设备属性

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  4. perl C/C++ 扩展(五)

    perl 的C++扩展,返回值为自定义类型. 在 perl C/C++扩展(三) 中,我已经介绍了,如何让perl 认识 c++的类,但是前面的介绍中,包括我参考的博客http://chunyemen ...

  5. 从MySQL高可用引出对高可用架构设计的一些思考

    高可用HA(High Availability)是分布式系统架构设计中必须考虑的因素之一,它通常是指,通过设计减少系统不能提供服务的时间. 假设系统一直能够提供服务,我们说系统的可用性是100%.如果 ...

  6. 关于web常见的安全问题

    一. Web攻击动机: 1.恶作剧: 2.关闭Web站点,拒绝正常服务: 3.篡改Web网页,损害企业名誉; 4.免费浏览收费内容; 5.盗窃用户隐私信息,例如手机号.Email等个人信息; 6.以用 ...

  7. [hdu1686] Oulipo【KMP】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1686 保存KMP模版,代码里P是模版串,next[]就是为它建立的.T是文本串,就是一般比较长的.nex ...

  8. UVA11292(排序贪心)

    笔者休息娱乐. ; int n, m, a; ll solve(int n, int m) { ll ans = ; priority_queue<int, vector<int>, ...

  9. MvcPager无刷新分页,包含搜索和跳转功能

    1.MVC无刷新分页和搜索(第一版)  http://pan.baidu.com/s/1eRQ7Ml8  密码:uqf7 出现的问题: 1)程序不走判断条件一直为false, 错误原因:1)可能没有引 ...

  10. MD5加密的方法

    #region MD5加密 /// <summary> /// MD5加密 /// </summary> /// <param name="strPwd&quo ...