UVA 1175 - Ladies' Choice
1175 - Ladies' Choice
稳定婚姻问题。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for (;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ; int pref[N][N],order[N][N],Boys[N],Girls[N],cur[N];
queue<int>q; // 求婚队列 void Link(int u,int v) {
int t = Girls[v];
if (t) {
Boys[t] = ;
q.push(t);
}
Boys[u] = v;
Girls[v] = u;
} void solve() {
int n = read();
for (int i=; i<=n; ++i) {
for (int j=; j<=n; ++j)
pref[i][j] = read(); // 男孩心中第j个喜欢的女孩
cur[i] = ; // 求婚对象
Boys[i] = ; // 男孩的
q.push(i);
}
for (int i=; i<=n; ++i) {
for (int j=; j<=n; ++j) {
int t = read();
order[i][t] = j; // 男孩在女孩中的排名
}
Girls[i] = ; // 女孩的
}
while (!q.empty()) {
int u = q.front();q.pop();
int v = pref[u][cur[u]++];
if (!Girls[v]) Link(u,v);
else if (order[v][u] < order[v][Girls[v]]) Link(u,v);
else q.push(u);
}
while (!q.empty()) q.pop();
for (int i=; i<=n; ++i)
printf("%d\n",Boys[i]);
}
int main() {
int Case = read();
while (Case--) {
solve();
if(Case) puts("");
}
return ;
}
UVA 1175 - Ladies' Choice的更多相关文章
- UVA 1175 Ladies' Choice 稳定婚姻问题
题目链接: 题目 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题 ...
- UVA 1175 Ladies' Choice 女士的选择(稳定婚姻问题,GS算法)
题意: 给出每个男的心目中的女神排序,给出每个女的心目中的男神排序,即两个n*n的矩阵,一旦任意两个非舞伴的男女同学觉得对方都比现任舞伴要好,他们就会抛弃舞伴而在一起.为了杜绝这种现象,求每个男的最后 ...
- 【UVAlive 3989】 Ladies' Choice (稳定婚姻问题)
Ladies' Choice Teenagers from the local high school have asked you to help them with the organizatio ...
- Ladies' Choice UVALive - 3989 稳定婚姻问题 gale_shapley算法
/** 题目: Ladies' Choice UVALive - 3989 链接:https://vjudge.net/problem/UVALive-3989 题意:稳定婚姻问题 思路: gale_ ...
- UVALive 3989 Ladies' Choice
Ladies' Choice Time Limit: 6000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...
- UVALive 3989 Ladies' Choice(稳定婚姻问题:稳定匹配、合作博弈)
题意:男女各n人,进行婚配,对于每个人来说,所有异性都存在优先次序,即最喜欢某人,其次喜欢某人...输出一个稳定婚配方案.所谓稳定,就是指未结婚的一对异性,彼此喜欢对方的程度都胜过自己的另一半,那么这 ...
- UVALive-3989 Ladies' Choice (稳定婚姻问题)
题目大意:稳定婚姻问题.... 题目分析:模板题. 代码如下: # include<iostream> # include<cstdio> # include<queue ...
- UVALive3989 Ladies' Choice —— 稳定婚姻问题 Gale - Shapely算法
题目链接:https://vjudge.net/problem/UVALive-3989 题解: 题意:有n个男生和n个女生.每个女生对男神都有个好感度排行,同时每个男生对每个女生也有一个好感度排行. ...
- LA 3989 - Ladies' Choice 稳定婚姻问题
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
随机推荐
- python+requests+json 接口测试思路示例
实际项目中用python脚本实现接口测试的步骤: 1 发送请求,获取响应 >>2 提取响应里的数据,对数据进行必要的处理 >>3 断言响应数据是否与预期一致 以豆瓣接口为例 ...
- Linux下apt-get的软件一般安装路径
apt-get安装目录和安装路径:apt-get 下载后,软件所在路径是:/var/cache/apt/archivesubuntu 默认的PATH为PATH=/home/brightman/bin: ...
- Power Designer逆向工程连接数据库创建pdm-oracle
1.进入菜单文件-Reverse Engineer-Database... 2.打开窗口,选择数据库版本,点击[确定] 3.打开窗口,选择Usering a data source: 4.如果已经有d ...
- BZOJ4520:[CQOI2016]K远点对(K-D Tree)
Description 已知平面内 N 个点的坐标,求欧氏距离下的第 K 远点对. Input 输入文件第一行为用空格隔开的两个整数 N, K.接下来 N 行,每行两个整数 X,Y,表示一个点 的坐标 ...
- HDU 1205 鸽巢原理
#include <bits/stdc++.h> using namespace std; long long abs_(long long a,long long b) { if(a&g ...
- 编译安装PHP开发环境
Linux 系统为 CentOS 7.2 1. 安装 Nginx 安装 Nginx 依赖包: # yum -y install zlib zlib-devel openssl openssl-deve ...
- 0.Python 爬虫之Scrapy入门实践指南(Scrapy基础知识)
目录 0.0.Scrapy基础 0.1.Scrapy 框架图 0.2.Scrapy主要包括了以下组件: 0.3.Scrapy简单示例如下: 0.4.Scrapy运行流程如下: 0.5.还有什么? 0. ...
- build.gradle中的dependencies
demo_myna中的build.gradle中的dependencies是依赖项目.比如之前开发的一个项目A,现在新的项目B要使用项目A的功能,那么把项目A作为类库关联进来,这样b就能直接使用A的功 ...
- 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
一,问题描述MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 ...
- 【luogu P3389 高斯消元法】 模板
题目链接: gauss消元求线性方程组的解. 这道题对于多解和无解都输出No solution #include <algorithm> #include <cstdio> # ...