题意:

有m个男孩和n个女孩,每个人都有一个舞蹈熟练度,用一个不超过100的正整数来表示。

一个男孩和一个女孩能够结为舞伴当且仅当两人的熟练度相差不超过1.

问最多能结成多少对舞伴

分析:

这是一个二分图最大匹配问题,如果男孩和女孩满足条件则添加一条边,然后用匈牙利算法求最大匹配即可。

这是匈牙利算法的模板

http://www.cnblogs.com/AOQNRMGYXLMV/p/3950653.html

题解中还给了一种贪心的解法。将两边的熟练度排序,然后匹配。

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
int a[maxn], b[maxn], line[maxn][maxn], used[maxn], girl[maxn];
int n, m; int main()
{
int cnt = ;
scanf("%d", &n);
for(int i = ; i < n; ++i) scanf("%d", &a[i]);
scanf("%d", &m);
for(int i = ; i < m; ++i) scanf("%d", &b[i]);
sort(a, a + n);
sort(b, b + m);
for(int i = ; i < n; ++i)
for(int j = ; j < m; ++j)
{
if(abs(a[i] - b[j]) <= )
{
cnt++;
b[j] = ; //标记这个妹子有舞伴了
break;
}
} printf("%d\n", cnt); 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 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 489B BerSU Ball (水题 双指针)

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

  5. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

  6. 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 ...

  7. codeforces 489B. BerSU Ball 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/B 题目意思:给出 n 个 boys 的 skills 和 m 个 girls 的 skills,要 ...

  8. CF 277.5 B.BerSU Ball 二分图的最大匹配 模版题

    题意:求二分图的最大匹配数量 模版如下: //二分图匹配(匈牙利算法的DFS实现) //初始化:g[][]两边顶点的划分情况 //建立g[i][j]表示i->j的有向边就可以了,是左边向右边的匹 ...

  9. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

随机推荐

  1. mysql 的数据文件

    mysql的数据文件 由于mysql的数据文件结构主要跟mysql的存储引擎相关,这里不做过多解释,具体查看各个引擎章节的内容 .首先上一段小辉老师的教程; 在MySQL 中每一个数据库都会在定义好( ...

  2. mac 搭建git服务器

      一.简单搭建,不提供复杂的权限管理: 远程建立git用户,并打开ssh服务:见http://www.cnblogs.com/whj198579/archive/2013/04/09/3009350 ...

  3. Wmware桥接网络虚拟机无法上网的问题

    之前装好的一个虚拟机,安装到本地的Wmware workstation的时候,发现无法上网. 虚拟机使用的是桥接模式:一开始怀疑IP被占用,修改后发现不起作用.    排查所有的网络配置,发现都没有问 ...

  4. 【系统Configmachine.config与自己的应用程序的App.config/Web.Config配置节点重复】解决方法

    自己的应用程序的App.config或Web.Config文件中与系统的C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Configmachine.co ...

  5. spring webservice 搭建出现的异常处理。异常: NAMESPACE_ERR: An attempt is made to create or change an object in a way whi

    异常:NAMESPACE_ERR: An attempt is made to create or change an object in a way whi---- 这是我自己写客户端调用webse ...

  6. 初识spring与quartz整合实现定时任务

    参考资料: http://kevin19900306.iteye.com/blog/1397744 引用自别人的博客: 特别注意一点,与Spring3.1以下版本整合必须使用Quartz1,最初我拿2 ...

  7. Android中ExpandableListView,每次只展示一个分组

    // 只允许打开一个分组 expandListView.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public ...

  8. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...

  9. 获取其它进程窗口中的状态栏信息(FindWindowEx GetWindowThreadProcessId OpenProcess SendMessage轮番轰炸)

    HWND hWnd = ::FindWindow(NULL, _T("XXXXX")); if(NULL == hWnd) { return ; } HWND hWndStatus ...

  10. ssm框架整合小结

    1.整合思路 一.Dao层:整合mybatis和spring 需要的jar包: 1.mybatis的jar包 2.Mysql数据库驱动 3.数据库连接池 4.Mybatis和spring的整合包. 5 ...