训练指南 UVALive - 3989(稳定婚姻问题)
ayout: post
title: 训练指南 UVALive - 3989(稳定婚姻问题)
author: "luowentaoaa"
catalog: true
mathjax: true
tags:
- 二分图匹配
- 图论
- 训练指南
Ladies' Choice
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e3+50;
const ll inf=1e10;
const ll INF = 1000000000;
const double eps=1e-5;
#define bug cout<<"bbibibibbbb="<<endl;
int pref[maxn][maxn],order[maxn][maxn],Next[maxn],future_husband[maxn],future_wife[maxn];
queue<int>Q;
void engage(int man,int woman){
int m=future_husband[woman];
if(m)future_wife[m]=0,Q.push(m);
future_wife[man]=woman;
future_husband[woman]=man;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
cin>>pref[i][j];
Next[i]=1;
future_wife[i]=0;
Q.push(i);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
int x;cin>>x;
order[i][x]=j;
}
future_husband[i]=0;
}
while(!Q.empty()){
int man=Q.front();Q.pop();
int woman=pref[man][Next[man]++];
if(!future_husband[woman])engage(man,woman);
else if(order[woman][man]<order[woman][future_husband[woman]])engage(man,woman);
else Q.push(man);
}
while(!Q.empty())Q.pop();
for(int i=1;i<=n;i++)cout<<future_wife[i]<<endl;
if(t)cout<<endl;
}
return 0;
}
训练指南 UVALive - 3989(稳定婚姻问题)的更多相关文章
- Ladies' Choice UVALive - 3989 稳定婚姻问题 gale_shapley算法
/** 题目: Ladies' Choice UVALive - 3989 链接:https://vjudge.net/problem/UVALive-3989 题意:稳定婚姻问题 思路: gale_ ...
- 训练指南 UVALive - 3126(DAG最小路径覆盖)
layout: post title: 训练指南 UVALive - 3126(DAG最小路径覆盖) author: "luowentaoaa" catalog: true mat ...
- 训练指南 UVALive - 3415(最大点独立集)
layout: post title: 训练指南 UVALive - 3415(最大点独立集) author: "luowentaoaa" catalog: true mathja ...
- 训练指南 UVALive - 4043(二分图匹配 + KM算法)
layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...
- 训练指南 UVALive - 5713(最小生成树 + 次小生成树)
layout: post title: 训练指南 UVALive - 5713(最小生成树 + 次小生成树) author: "luowentaoaa" catalog: true ...
- 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树)
layout: post title: 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树) author: "luowentaoaa" ca ...
- 训练指南 UVALive - 3713 (2-SAT)
layout: post title: 训练指南 UVALive - 3713 (2-SAT) author: "luowentaoaa" catalog: true mathja ...
- 训练指南 UVALive - 4287 (强连通分量+缩点)
layout: post title: 训练指南 UVALive - 4287 (强连通分量+缩点) author: "luowentaoaa" catalog: true mat ...
- 训练指南 UVALive - 5135 (双连通分量)
layout: post title: 训练指南 UVALive - 5135 (双连通分量) author: "luowentaoaa" catalog: true mathja ...
随机推荐
- POJ2406 Power Strings 【KMP 或 后缀数组】
电源串 时间限制: 3000MS 内存限制: 65536K 提交总数: 53037 接受: 22108 描述 给定两个字符串a和b,我们定义a * b是它们的连接.例如,如果a =" ...
- Leetcode 45. Jump Game II(贪心)
45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: Given an array of non ...
- mmall项目之问题一(mavenplugin问题)
在进行mybatis逆向工程到时候,报错,提示maven plugin 错误,提示missing..... 解决办法: 因为之前到pom中忘记了加版本信息,添加后错误消失:
- Join/remove server into/from windows domain PS script
Join server into windows domain PS script $username = "ad-domain\admin" $Password = " ...
- bzoj 1692: [Usaco2007 Dec]队列变换 ——二分+hash
Description FJ打算带他的N(1 <= N <= 30,000)头奶牛去参加一年一度的“全美农场主大奖赛”.在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席 ...
- vueJS 一天上手到精通
近来用vuejs, vuejs和angular的不同在于它直接暴露了一个构造函数,而后在里面写各种config, 和模板再相对,而且vuejs也有对应的模板双向绑定机制,这样就使开发非常简单容易,虽然 ...
- [bzoj3277==bzoj3473]出现k次子串计数——广义后缀自动机+STL
Brief Description 给定n个字符串,对于每个字符串,您需要求出在所有字符串中出现次数大于等于k次的子串个数. Algorithm Design 先建立一个广义后缀自动机,什么是广义后缀 ...
- mongoDB的简单使用
1.客户端连接: ./mongo 2.数据库 一个mongodb中可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实 ...
- doxygen使用
前言 下面主要讲解linux下Doxygen命令行实现html文档生成的操作,当然也有界面版本操作方式,linux下安装doxygen-gui即可通过doxywizard开启界面操作,windows下 ...
- 安全测试===BurpSuite使用教程-附安装包
jar包: Burpsuite1.6亲测可用.zip 我的jdk版本: 运行包: >>> java -cp BurpLoader.jar;burpsuite_pro_v1.6.jar ...