UVALive-3989 Ladies' Choice (稳定婚姻问题)
题目大意:稳定婚姻问题。。。。
题目分析:模板题。
代码如下:
# include<iostream>
# include<cstdio>
# include<queue>
# include<cstring>
# include<algorithm>
using namespace std;
# define LL long long
# define REP(i,s,n) for(int i=s;i<n;++i)
# define CL(a,b) memset(a,b,sizeof(a))
# define CLL(a,b,n) fill(a,a+n,b) const int N=1005;
int fu_husband[N],fu_wife[N],order[N][N],pref[N][N],nxt[N],n;
queue<int>q; void engage(int man,int woman)
{
int k=fu_husband[woman];
if(k){
fu_wife[k]=0;
q.push(k);
}
fu_wife[man]=woman;
fu_husband[woman]=man;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
while(!q.empty()) q.pop();
REP(i,1,n+1){
REP(j,1,n+1) scanf("%d",&pref[i][j]);
nxt[i]=1;
fu_wife[i]=0;
q.push(i);
}
REP(i,1,n+1){
REP(j,1,n+1){
int x;
scanf("%d",&x);
order[i][x]=j;
}
fu_husband[i]=0;
}
while(!q.empty()){
int man=q.front();
q.pop();
int woman=pref[man][nxt[man]++];
if(!fu_husband[woman])
engage(man,woman);
else if(order[woman][man]<order[woman][fu_husband[woman]])
engage(man,woman);
else
q.push(man);
}
REP(i,1,n+1) printf("%d\n",fu_wife[i]);
if(T) printf("\n");
}
return 0;
}
UVALive-3989 Ladies' Choice (稳定婚姻问题)的更多相关文章
- LA 3989 - Ladies' Choice 稳定婚姻问题
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVALive 3989 Ladies' Choice
Ladies' Choice Time Limit: 6000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...
- UVA 1175 Ladies' Choice 稳定婚姻问题
题目链接: 题目 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题 ...
- UVALive 3989 Ladies' Choice(稳定婚姻问题:稳定匹配、合作博弈)
题意:男女各n人,进行婚配,对于每个人来说,所有异性都存在优先次序,即最喜欢某人,其次喜欢某人...输出一个稳定婚配方案.所谓稳定,就是指未结婚的一对异性,彼此喜欢对方的程度都胜过自己的另一半,那么这 ...
- UVALive3989 Ladies' Choice —— 稳定婚姻问题 Gale - Shapely算法
题目链接:https://vjudge.net/problem/UVALive-3989 题解: 题意:有n个男生和n个女生.每个女生对男神都有个好感度排行,同时每个男生对每个女生也有一个好感度排行. ...
- UVALive 3989 Ladies' Choice
经典的稳定婚姻匹配问题 UVALive - 3989 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: ...
- UVALive 3989Ladies' Choice(稳定婚姻问题)
题目链接 题意:n个男生和女生,先是n行n个数,表示每一个女生对男生的好感值排序,然后是n行n列式每一个男生的好感值排序,输出N行,即每个女生在最好情况下的男生的编号 分析:如果是求女生的最好情况下, ...
- Ladies' Choice UVALive - 3989 稳定婚姻问题 gale_shapley算法
/** 题目: Ladies' Choice UVALive - 3989 链接:https://vjudge.net/problem/UVALive-3989 题意:稳定婚姻问题 思路: gale_ ...
- 【UVAlive 3989】 Ladies' Choice (稳定婚姻问题)
Ladies' Choice Teenagers from the local high school have asked you to help them with the organizatio ...
- 训练指南 UVALive - 3989(稳定婚姻问题)
ayout: post title: 训练指南 UVALive - 3989(稳定婚姻问题) author: "luowentaoaa" catalog: true mathjax ...
随机推荐
- 沈阳网络赛F-Fantastic Graph【贪心】or【网络流】
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- OGG双向复制
注意:在进行如下配置之前,先在源数据库(原来的目标数据库)端添加辅助的redolog配置: 1.SQL> alter database add supplemental log dat ...
- Oracle开发 之 主-外键约束FK及约束的修改
试验环境: 1)数据库版本:oracle 11.2.0.4 2)建表脚本:以scott的dept及emp表为基础. 父表:dept -- Create table create table DEPT ...
- Andrew Ng机器学习公开课笔记 -- Generalized Linear Models
网易公开课,第4课 notes,http://cs229.stanford.edu/notes/cs229-notes1.pdf 前面介绍一个线性回归问题,符合高斯分布 一个分类问题,logstic回 ...
- UVA 624 ---CD 01背包路径输出
DescriptionCD You have a long drive by car ahead. You have a tape recorder, but unfortunately your b ...
- Linux eventfd分析
2017-07-20 eventfd在linux中是一个较新的进程通信方式,和信号量等不同的是event不仅可以用于进程间的通信,还可以用户内核发信号给用户层的进程.eventfd在virtIO后端驱 ...
- TCP协议通讯工作原理
TCP协议通讯工作原理 一.TCP三次握手 传输控制协议(Transport Control Protocol)是一种面向连接的,可靠的传输层协议.面向连接是指一次正常的TCP传输需要通过在TCP ...
- [py]多态的理解
多态 不同的数据类型,执行相同的方法,产生的状态不同 不同对象调用相同的方法(运行时候的绑定状态) #!/usr/bin/env python # coding=utf-8 class H2O: de ...
- 关于ML的思考讲座-周zh-11.30日
1.深度神经网络 1.以往神经网络采用单或双隐层结构,虽然参照了生物上的神经元,但是从本质上来说还是数学,以函数嵌套形成. 2.通常使用的激活函数是连续可微(differentiable)的,sigm ...
- 更好的利用配置文件和importlib
需求:做不同的操作时只需修改配置文件即可完成 # message/email.py from .base import Base # 子类必须实现send方法,否则抛出异常 class Email(B ...