题目大意:稳定婚姻问题。。。。

题目分析:模板题。

代码如下:

# 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 (稳定婚姻问题)的更多相关文章

  1. LA 3989 - Ladies' Choice 稳定婚姻问题

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  2. UVALive 3989 Ladies' Choice

    Ladies' Choice Time Limit: 6000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...

  3. UVA 1175 Ladies' Choice 稳定婚姻问题

    题目链接: 题目 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题 ...

  4. UVALive 3989 Ladies' Choice(稳定婚姻问题:稳定匹配、合作博弈)

    题意:男女各n人,进行婚配,对于每个人来说,所有异性都存在优先次序,即最喜欢某人,其次喜欢某人...输出一个稳定婚配方案.所谓稳定,就是指未结婚的一对异性,彼此喜欢对方的程度都胜过自己的另一半,那么这 ...

  5. UVALive3989 Ladies' Choice —— 稳定婚姻问题 Gale - Shapely算法

    题目链接:https://vjudge.net/problem/UVALive-3989 题解: 题意:有n个男生和n个女生.每个女生对男神都有个好感度排行,同时每个男生对每个女生也有一个好感度排行. ...

  6. UVALive 3989 Ladies&#39; Choice

    经典的稳定婚姻匹配问题 UVALive - 3989 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format:  ...

  7. UVALive 3989Ladies' Choice(稳定婚姻问题)

    题目链接 题意:n个男生和女生,先是n行n个数,表示每一个女生对男生的好感值排序,然后是n行n列式每一个男生的好感值排序,输出N行,即每个女生在最好情况下的男生的编号 分析:如果是求女生的最好情况下, ...

  8. Ladies' Choice UVALive - 3989 稳定婚姻问题 gale_shapley算法

    /** 题目: Ladies' Choice UVALive - 3989 链接:https://vjudge.net/problem/UVALive-3989 题意:稳定婚姻问题 思路: gale_ ...

  9. 【UVAlive 3989】 Ladies' Choice (稳定婚姻问题)

    Ladies' Choice Teenagers from the local high school have asked you to help them with the organizatio ...

  10. 训练指南 UVALive - 3989(稳定婚姻问题)

    ayout: post title: 训练指南 UVALive - 3989(稳定婚姻问题) author: "luowentaoaa" catalog: true mathjax ...

随机推荐

  1. Oracle在linux下命令行无法使用退格键退格,无法使用上下键切换历史命令的解决办法

    使用xshell等客户端登录oracl时在命令行无法使用退格键也无法使用上下键切换历史命令可以使用rlwrap解决 1,linux环境 2,下载rlwrap wget http://files.cnb ...

  2. PL/SQL集合(一):记录类型(TYPE 类型名称 IS RECORD)

    记录类型 利用记录类型可以实现复合数据类型的定义: 记录类型允许嵌套: 可以直接利用记录类型更新数据. 传统操作的问题 对于Oracle数据类型,主要使用的是VARCHAR2.NUMBER.DATE等 ...

  3. Convolution and polynomial multiplication

    https://www.mathworks.com/help/matlab/ref/conv.html?s_tid=gn_loc_drop conv Convolution and polynomia ...

  4. 系统中同时有 python2和 python3,怎么让 ipython 选择不同的版本启动?

    已经安装的情况下: > which ipython /usr/local/bin/ipython > cat /usr/local/bin/ipython  #!/usr/local/op ...

  5. Monkey Tradition---LightOj1319(中国剩余定理模板)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1319 题意:有 n 个猴子,n 棵树,树的高度为 L ,每个猴子刚开始的时候都在树的底 ...

  6. 山寨HTML5API classList类

    preface 认为自己去写一些类,你真的会找到自己不足的地方.事实上厉害不是你实现一个类.而是你怎样去设计一个类,能让开发人员更加easy操作. 对于这个操作样式,能够通过javascript訪问s ...

  7. golang 复制对象的正确做法

    需求 实际运用种,传参是一对象指针,现在如何最简便地复制一对象? 实现 坑:&*  先拿到值再指针? package main import ( "time" " ...

  8. java的==和equal的区别(一)

    java的==和equal的区别 “==”是用来比较两个String对象在内存中的存放地址是否相同的.例如, 1 2 3 4 5 6 7 8 9 String test1 = "test&q ...

  9. h5前端项目常见问题汇总

    原文作者:FrontEndZQ 原文链接:https://github.com/FrontEndZQ/HTML5-FAQ H5项目常见问题及注意事项 Meta基础知识: H5页面窗口自动调整到设备宽度 ...

  10. linux的浅谈io操作

    系统默认设定 名称类型文件描述符操作标准输入standard input0<,<< 标准输出standard output1>,>> 标准错误输出standard ...