首页 > 代码库 > Codeforces Round #277.5 (Div. 2) b
Codeforces Round #277.5 (Div. 2) b
/** * @brief Codeforces Round #277.5 (Div. 2) b * @file b.c * @author 面码 * @created 2014/11/18 17:22 * @edited 2014/11/18 17:22 * @type greedy * */ #include <stdio.h> #define MAXN 110 #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) > (b) ? (b) : (a)) #define abs(a) ((a) > 0 ? (a) : (0 - (a))) int n, m; int girls[MAXN]; int boys[MAXN]; int tot; int main() { int i, val; #ifdef DEBUG freopen("./in", "r", stdin); freopen("./out", "w", stdout); #endif scanf("%d", &n); for(i = 0; i < n; i++){ scanf("%d", &val); ++boys[val]; } scanf("%d", &m); for(i = 0; i < m; i++){ scanf("%d", &val); ++girls[val]; } /*greedy here, we must see the problem from boys or girls, this is very important*/ tot = 0; for(i = 1; i <= 100; i++){ val = min(boys[i], girls[i - 1]); tot += val; boys[i] -= val; girls[i - 1] -= val; val = min(boys[i], girls[i]); tot += val; boys[i] -= val; girls[i] -= val; val = min(boys[i], girls[i + 1]); tot += val; boys[i] -= val; girls[i + 1] -= val; } printf("%d\n", tot); return 0; }
Codeforces Round #277.5 (Div. 2) b
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。