题目链接:http://codeforces.com/problemset/problem/489/B

题目意思:给出 n 个 boys 的 skills 和 m 个 girls 的 skills,要求成 pair 的条件为,男和女的 skill 差值最多只能为 1。问成 pair 最多是多少。

这个不太难,关键是要考虑周全。

  对于某个人,假设他(男)的 skill 值为 i,那么跟他成 pair 的人的 skill 值,只有三种:i-1,i,i+1。跟他成对的女要减少一个。然后女的那边也要搜一遍,再输出较大的就是答案了。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
int a[maxn], b[maxn]; int get_num(int ta[], int tb[])
{
int num = ;
for (int i = ; i <= ; i++)
{
if (ta[i])
{
for (int j = ; j < ta[i]; j++)
{
if (tb[i-])
{
tb[i-]--;
num++;
}
else if (tb[i])
{
tb[i]--;
num++;
}
else if (tb[i+])
{
tb[i+]--;
num++;
}
}
}
}
return num;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif int n, m, input;
while (scanf("%d", &n) != EOF)
{
memset(a, , sizeof(a));
memset(b, , sizeof(b)); for (int i = ; i < n; i++)
{
scanf("%d", &input);
a[input]++;
}
scanf("%d", &m);
for (int i = ; i < m; i++)
{
scanf("%d", &input);
b[input]++;
}
int ans = ;
ans = max(get_num(a, b), get_num(b, a));
printf("%d\n", ans);
}
return ;
}

codeforces 489B. BerSU Ball 解题报告的更多相关文章

  1. CodeForces 489B BerSU Ball (贪心)

    BerSU Ball 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/E Description The Berland Stat ...

  2. CodeForces 489B BerSU Ball (水题 双指针)

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

  3. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  4. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  5. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  6. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

  7. codeforces 591A. Wizards' Duel 解题报告

    题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...

  8. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  9. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

随机推荐

  1. 学习笔记-KMP算法

    按照学习计划和TimeMachine学长的推荐,学习了一下KMP算法. 昨晚晚自习下课前粗略的看了看,发现根本理解不了高端的next数组啊有木有,不过好在在今天系统的学习了之后感觉是有很大提升的了,起 ...

  2. Spring JdbcTemplate 的使用与学习(转)

    紧接上一篇 (JdbcTemplate是线程安全的,因此可以配置一个简单的JdbcTemplate实例,将这个共享的实例注入到多个DAO类中.辅助的文档) Spring DAO支持 http://ww ...

  3. BZOJ1046 [HAOI2007]上升序列

    Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...

  4. TortoiseSVN客户端如何更改新的URL

    问题: 我们的服务器换了新的URL地址,这时候我们本地的SVN访问帐号和地址就要重新定义了. 解决步骤: 1:重新定义SVN的URL,右键(TortoiseSVN) → Relocate → 输入你新 ...

  5. POJ 1789Truck History(pirme)

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22648   Accepted: 8781 De ...

  6. Linux创建用户命令

    创建用户.设置密码.修改用户.删除用户: useradd testuser   创建用户testuser passwd testuser   给已创建的用户testuser设置密码 说明:新创建的用户 ...

  7. JavaScript中call、apply、bind、slice的使用

    1.参考资料 http://www.cnblogs.com/coco1s/p/4833199.html   2.归结如下 apply . call .bind 三者都是用来改变函数的this对象的指向 ...

  8. CSS transition 过渡 详解

    transition 过渡 IE10.Firefox.Chrome.Opera 支持 transition 属性. Safari 需要前缀 -webkit-. Chrome 25 以及更早版本需要前缀 ...

  9. Log4j使用教程 log4:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).

    1.Logger类 通过Logger类的静态方法Logger.getRootLogger得到RootLogger.所有其他的loggers是通过静态方法Logger.getLogger来实例化并获取的 ...

  10. 关闭 ubuntu System program problem detected

    每次开机都出现: System program problem detected 很麻烦,关闭方法: vim /etc/default/apport # set this to 0 to disabl ...