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).给出值 ...
随机推荐
- 【CodeForces 471A】MUH and Sticks
题 题意 给你六根木棍的长度,熊需要头比身体短,大象需要头和身体一样,四肢要一样长,否则就是外星人.请你判断能组成哪一个. 分析 暴力,循环看一下每根有几根相同的,然后如果有四根都是有四根相同的&am ...
- win10 1607 安装密钥 GVLK
Core=YTMG3-N6DKC-DKB77-7M9GH-8HVX7 Professional=VK7JG-NPHTM-C97JM-9MPGT-3V66T Enterprise=XGVPP-NMH47 ...
- this的使用
1.使用this调用本类中的属性 class Person{ private String name; private int age; public Person(String name,int a ...
- SGU 275 To xor or not to xor
time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard output: standard The ...
- POJ1995(整数快速幂)
http://poj.org/problem?id=1995 题意:求(A1^B1 + A2^B2 + .....Ah^Bh)%M 直接快速幂,以前对快速幂了解不深刻,今天重新学了一遍so easy ...
- 新建android工程的时候eclipse没有生成MainActivity和layout布局
一.新建android工程的时候eclipse没有生成MainActivity和layout布局 最近由于工作上的原因,开始学习Android开发,在入门的时候就遇到了不少的坑,遇到的第一个坑就是&q ...
- 初学JDBC,调用存储过程
在JDBC简单封装的基础上实现 public class UserDao{ public static void testGetUser(String userName) throws Excepti ...
- motto5
No matter what others say,I won't forsake my priciples.
- windows下使用批处理文件调用python程序
这个随笔涉及到几个批处理脚本得知识点. windows的start命令, 启动另一个窗口运行指定的程序或命令. windows的call命令, 从批处理程序调用另一个程序, 直到被调用程序退出, 再继 ...
- update操作多张表
sql 语句多张表UPDATE用法一.当用一个表中的数据来更新另一个表中的数据,T-SQL提供多种写法(下面列出了二种),但建议用第一种写法,虽然传统,但结构清晰.飞.飞Asp技术乐园并且要注意,当用 ...