codeforces 489B. BerSU Ball 解题报告
题目链接: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 解题报告的更多相关文章
- CodeForces 489B BerSU Ball (贪心)
BerSU Ball 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/E Description The Berland Stat ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
随机推荐
- Oracle中的伪列
分页查询中,需要用到伪列rownum,代码如下: select * from (select rownum rn, name from cost where rownum <= 6) where ...
- jdbcTemplate的配置
相关jar 包 package sfk.bbs.test.springjsbctempletTest; import static org.junit.Assert.*; import java.sq ...
- 五种开源协议的比较(BSD_Apache_GPL_LGPL_MIT)
现今存在的开源协议很多,而经过Open Source Initiative组织通过批准的开源协议目前有58种(http://www.opensource.org/licenses/alphabetic ...
- PL/0编译器(java version) - Interpreter.java
1: package compiler; 2: 3: import java.io.BufferedReader; 4: import java.io.BufferedWriter; 5: imp ...
- core dump gdb调试
core dump又叫核心转储, 当程序运行过程中发生异常, 程序异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 叫core dump. (linux中如果内存越界会收到SIG ...
- std::stringstream
使用 std::stringstream,小心 内存! 适时 清空 缓冲 …… 2007年12月14日 星期五 : stringstream是个好东西,网上有不少文章,讨论如何用它实现各种数据类型的转 ...
- try、catch 和 throw 语句 (了解)
C++ 异常使用 try.catch 和 throw 关键字. 引发表达式指示错误或异常情况. 可以将任何类型的对象用作引发表达式的操作数. 此对象通常用于传达有关错误的信息. 通常,应使用在标准库中 ...
- Visual Studio IIS Express 不支持.json后缀的mime类型
vs默认web调试工具中并不支持.json后缀的mime类型. 如何解决,两个方案: 局部单应用:web.config: <system.webServer> .... <stati ...
- ios 图片尺寸
- zencart资源
http://www.zen-cart.cn/ http://www.ezencart.com/