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 ...
随机推荐
- Galaxy2D Game Engine 4.2 开发版发布
Update: ◆删除Graph_GetRenderTarget()函数,添加Graph_CopyBackBuffer()/Graph_CopyRanderTarget()函数 ◆Graph_EndS ...
- C# 生成二维码扫码
转载 https://www.cnblogs.com/jys509/p/4592539.html 引用ThoughtWorks.QRCode.dll (源代码里有) 1.简单二维码生成及解码代码: / ...
- [URLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; _sessio ...
- Spring Boot 集成 logback日志
application.properties 配置logback.xml 路径注:如果logback.xml在默认的 src/main/resources 目录下则不需要配置application.p ...
- c语言函数参数类似继承的传递
函数的参数如果是一个父结构的指针, 这个结构包含在另一个子结构中, typedef struct test_node_one test_node_one_t; typedef struct test_ ...
- 转载---JQuery 对 Select option 的操作
下拉框: <select id="selectID" > <option value="1">1</option& ...
- 图表相同数据会自动合并问题(finereport)
finereport中,对于图表的操作,当遇到需要显示多个重复分类下的多个值时,由于自动合并相同数据,无法达到效果反复查询手册无果后,困扰好久,终想到了一个解决的办法:1.给查询的数据添加个列序号,每 ...
- 如何解决button,a,input标签自带蓝色边框
通常我们会设置该标签outline:0;但是我在使用iview自带的button组件的时候,设置无效,经过测试只要设置 :focus{ outline:0; } 即可,方便有效
- uva-757-贪心
题意:有个人要去湖里钓鱼,总共有N个湖,排成一个序列,用字母P表示湖,从湖pi 到 pi+1(下一个湖)需要ti个五分钟. 并且,每个湖里可钓出来的鱼每过五分钟就减少di.如果产出的鱼小于等于di.那 ...
- 利用pyinstaller生成exe之后,运行不能正常产生结果文件问题记录
https://segmentfault.com/q/1010000011284617/a-1020000011493026 在此链接已解决问题,现在在这里在详细记录一次 问题描述: 利用pychar ...