HDU 1522 Marriage is Stable 稳定婚姻匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1522

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define me(a,b) memset(a,b,sizeof(a))
#define N 552
typedef long long ll;
using namespace std; int girl[N],boy[N],n,b[N][N],g[N][N];
bool vis[N][N];
string s,e;
map<string,int>bb,gg;
string bbb[N],ggg[N]; void init()
{
me(girl,-);
me(boy,-);
me(vis,);
bb.clear();
gg.clear();
} void stable_march()
{
queue<int>q;
for(int i=;i<n;i++)
q.push(i);
while(!q.empty())
{
int f=q.front();
q.pop();
for(int i=;i<n;i++)
{
int tmp=b[f][i];
if(vis[f][tmp])
{
continue;
}
vis[f][tmp]=;
if(girl[tmp]==-)
{
girl[tmp]=f;
boy[f]=tmp;
break;
}
else if(g[tmp][girl[tmp]]<g[tmp][f])
{
q.push(girl[tmp]);
girl[tmp]=f;
boy[f]=tmp;
break;
}
}
}
} int main()
{
//freopen("in.txt","r",stdin);
while(cin>>n)
{
init();
for(int i=;i<n;i++)
{
cin>>s;
bbb[i]=s;
bb[s]=i;
if(i==)
for(int j=;j<n;j++)
{
cin>>e;
b[i][j]=j;
gg[e]=j;
ggg[j]=e;
}
else
for(int j=;j<n;j++)
{
cin>>e;
b[i][j]=gg[e];
}
}
for(int i=;i<n;i++)
{
cin>>s;
int t=gg[s];
for(int j=n-;j>-;j--)
{
cin>>e;
g[t][bb[e]]=j;
}
}
stable_march();
for(int i=;i<n;i++)
{
cout<<bbb[i]<<' '<<ggg[boy[i]]<<endl;
}
cout<<endl;
}
}
HDU 1522 Marriage is Stable 稳定婚姻匹配的更多相关文章
- HDU 1522 Marriage is Stable 【稳定婚姻匹配】(模板题)
<题目链接> 题目大意: 给你N个男生和N个女生,并且给出所有男生和女生对其它所有异性的喜欢程度,喜欢程度越高的两个异性越容易配对,现在求出它们之间的稳定匹配. 解题分析: 稳定婚姻问题的 ...
- HDU1522 稳定婚姻匹配 模板
Marriage is Stable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 【HDU1914 The Stable Marriage Problem】稳定婚姻问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1914 题目大意:问题大概是这样:有一个社团里有n个女生和n个男生,每位女生按照她的偏爱程度将男生排序, ...
- POJ 3487 The Stable Marriage Problem(稳定婚姻问题 模版题)
Description The stable marriage problem consists of matching members of two different sets according ...
- HDU1914 稳定婚姻匹配
The Stable Marriage Problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (J ...
- HDU - 3081 Marriage Match II 【二分匹配】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...
- 【稳定婚姻问题】【HDU1435】【Stable Match】
2015/7/1 19:48 题意:给一个带权二分图 求稳定匹配 稳定的意义是对于某2个匹配,比如,( a ---- 1) ,(b----2) , 如果 (a,2)<(a,1) 且(2,a)& ...
- @hdu - 6687@ Rikka with Stable Marriage
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个稳定婚姻匹配问题,其中第 i 个男生与第 j 个女生之间 ...
- 最大团&稳定婚姻系列
[HDU] 1530 Maximum Clique 1435 Stable Match 3585 maximum shortest distance 二分+最大团 1522 Marriage is ...
随机推荐
- BAT开发中,ChromeDriver版本兼容性检查
打开解决方案的Nuget包管理器,选择合适的版本,安装即可.版本的兼容性检查,见上一篇blog(初次使用BAT,请检查Chrome浏览器和ChromeDriver兼容性 https://www.cnb ...
- EXT.net 图标靠右排列
toolbar1.Items.Add(Button_1); toolbar1.Items.Add(Button_2); toolbar1.Items.Add(Button_3); toolbar1.I ...
- Jmeter发送邮件功能SMTP Sampler
介绍Jmeter的发送邮件功能,使用的Sampler是SMTP Sampler,详细说明每个配置项的功能 从上往下介绍需要用到的配置项: Server settings Server: 服务器地址 P ...
- 极速认识RSS!
在解释RSS是什么之前,让我先来举个栗子. 大家都能在街道看到许多海报栏.在那里,会贴出各种各样最新的消息,比如哪个系要开讲座了.星期二晚上的电影放什么.二手货转让等 等.只要看一下海报栏,就会对学校 ...
- Skyline TerraExplorer 7.0- 扩展信息树
Skyline TerraExplorer V7增加了一个扩展信息树的控件TEInformationWindowEx. 该控件能够将TE3DWindowEx窗口里面的对象显示为信息树的方式.TEIn ...
- 让WebStrom支持SSH协议的子项目
让WebStrom支持SSH协议的子项目 在大项目中, 经常会遇到子项目(submodule)使用ssh的情形, 但是WebStrom不直接支持它. 下面以MAC为例,在PC中的处理类似. 打开ter ...
- opencv人脸检测,旋转处理
年会签到,拍自己的大头照,有的人可能会拍成横向的,需要旋转,用人脸检测并修正它(图片). 1. 无脑检测步骤为: 1. opencv 读取图片,灰度转换 2. 使用CascadeClassifier( ...
- py3,休息时间玩点小把戏
100以内奇数: ls = [x for x in range(100) if x % 2 == 1] 100以内偶数: ls = list(x for x in range(100) if x % ...
- Win7+ 电脑 休眠 自动唤醒
https://jingyan.baidu.com/article/3ea51489d905df52e71bba6b.html
- dojo里添加目录树
其实循环生成目录树这个方法不仅仅局限于在使用dojo的情况下,只要明白了其中的原理,在任何一种语言下都能动态循环生成. 1. 数据结构 在这里先说明一下数据结构,我这里循环生成目录树的数据结构是像这样 ...