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

题目分析:模板题。

代码如下:

# 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. FZU 2107 Hua Rong Dao(dfs)

    Problem 2107 Hua Rong Dao Accept: 318 Submit: 703 Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...

  2. php5.6 的curl开启和之前的不太一样了,搞了半天,记录下

    设置电脑环境变量中的->系统变量(注:不是用户变量) 新建 PHP_HOME 值 D:\php /PHP 根目录 Path 增加 ;%PHP_HOME%;%PHP_HOME%\ext       ...

  3. 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask

    参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...

  4. Git学习-->GitLab如何修改时区?

    一.背景 今天有同事在GitLab上查看时间的时候,发现GitLab上显示的时间和提交的时间不一致. 本地时间现在为:2017-11-28 11:43 查看本地代码提交的时间为:2017-11-28 ...

  5. 正则表达式python

    import re # re.match() 能够匹配出以xxx开头的字符串 ret = re.match(r"H", "Hello Python") # pr ...

  6. mysql 数据操作 单表查询 having 过滤 练习

    1. 查询各岗位内包含的员工个数小于2的岗位名.岗位内包含员工名字.个数 mysql> select post,group_concat(name),count(id) from employe ...

  7. .NET 海量数据处理,并处理事务问题

    1.下面是一个C#的控制台以代码来说明处理 using System.Data.SqlClient; class Program { static void Main() { string conne ...

  8. 20155307 2016-2017-2 《Java程序设计》第8周学习总结

    20155307 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 日志API:使用日志的起点是Logger类,要取得Logger类,必须使用Logger的静态 ...

  9. nginx重启 failed (98: Address already in use)

    启动nginx服务,无法正常启动,一查log日志,发现如题错误信息. 问题描述:地址已被使用.可能nginx服务卡死了,导致端口占用,出现此错误. 查看端口 netstat -ntpl 杀掉进程   ...

  10. JS事件监听手机屏幕触摸事件 Touch

    JS移动客户端--触屏滑动事件 移动端触屏滑动的效果其实就是图片轮播,在PC的页面上很好实现,绑定click和mouseover等事件来完成.但是在移动设备上,要实现这种轮播的效果,就需要用到核心的t ...