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 ...
随机推荐
- 让ASP.NET OutputCache使用http.sys kernel-mode cache
在默认情况下,http.sys kerne mode cache只缓存静态文件. 那我们如何让ASP.NET OutputCache直接使用http.sys kerne mode cache?这样缓存 ...
- Mysql和sqlite数据库操作心得
经过最近一段时间的实际工作发现,原来只是认为Mysql和sqlite是分别独立的,数据传输和共享或有障碍,其实这是一个误区.当我们想要将sqlite中的数据存放到mysql中,最好的方法就是利用中间文 ...
- scrapy爬虫系列之六--模拟登录
功能点:如何发送携带cookie访问登录后的页面,如何发送post请求登录 爬取网站:bilibili.github 完整代码:https://files.cnblogs.com/files/book ...
- Python开发【模块】:M2Crypto RSA加密、解密
M2Crypto 模块 快速安装: # 环境centos7.0,提前装好openssl(自行百度安装),windows装不上,暂不考虑了 [root@localhost ~]# pip install ...
- Python性能鸡汤(转)
英文原文:http://blog.monitis.com/index.php/2012/02/13/python-performance-tips-part-1/ 英文原文:http://blog.m ...
- 1107 Social Clusters[并查集][难]
1107 Social Clusters(30 分) When register on a social network, you are always asked to specify your h ...
- JOJ1202。重新操刀ACM,一天一练!做个简单的题目温习。
http://ac.jobdu.com/problem.php?pid=1202 题目描述: 对输入的n个数进行排序并输出. 输入: 输入的第一行包括一个整数n(1<=n<=100). ...
- mono安装
linux上的DotNET,安装mono 当前,在Linux系统上架设ASP.NET网站.建设WEB应用工程项目已经在国内流行起来,而“Mono+Jexus”架构模式是Linux承载ASP.NET企业 ...
- python开发之路目录
Python 目录 基础 python入门 python数据类型.字符编码.文件处理 python函数基础 python函数进阶 python装饰器函数 python装饰器函数 python递归函数 ...
- uva11732 Trie转化
有40001 个单词每个单词长度不超过1000,每个两个单词之间都要比较求要比较次数 int strcmp(char *s,char *t){ int i; for(i = 0; s[i]==t[i] ...