当前位置:网站首页>HDU 1522 marriage is stable
HDU 1522 marriage is stable
2022-07-28 04:54:00 【gongyuandaye】
The question : Stable marriage matching problem , Board question .
Answer key : Stable marriage matching
Fortunately, I did this problem , There was something wrong with the previous board ,1435 The data is too weak .
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#define ll long long
#define pii pair<int, int>
using namespace std;
// Stable marriage matching
const int maxn = 505;
string str[maxn * 2];
int n;
int boy_love_who[maxn][maxn], girl_love_fir[maxn][maxn];
int boy[maxn], girl[maxn], kth[maxn];
inline void G_S() {
for (int i = 1; i <= n; i++) boy[i] = girl[i] = kth[i] = 0;
bool flag, no = 0;
int xx = 1;
while (true) {
flag = false;
for (int i = 1; i <= n; i++) {
if (!boy[i]) {
int g = boy_love_who[i][++kth[i]];
if (kth[i] > n) {
no = 1;
break;
}
if (!girl[g]) {
girl[g] = i;
boy[i] = g;
continue;
}
else if (girl_love_fir[g][i] < girl_love_fir[g][girl[g]]) {
boy[girl[g]] = 0;
girl[g] = i;
boy[i] = g;
}
flag = true;
}
}
if (no) break;
if (!flag) break;
}
if (no) puts("Impossible");
else for (int i = 1; i <= n; i++) cout << str[girl[i]] << " " << str[i + n] << endl;
}
int main() {
while (~scanf("%d", &n)) {
map<string, int> m, m2;
int id = 0;
string s;
for (int i = 1; i <= n; i++) {
cin >> s;
m[s] = i;
str[i] = s;
for (int j = 1; j <= n; j++) {
cin >> s;
if (!m2[s]) {
m2[s] = ++id;
str[id + n] = s;
}
boy_love_who[i][j] = m2[s];
}
}
for (int i = 1; i <= n; i++) {
cin >> s;
int x = m2[s];
for (int j = 1; j <= n; j++) {
cin >> s;
girl_love_fir[x][m[s]] = j;
}
}
G_S();
}
return 0;
}
边栏推荐
- Machine learning and deep learning -- normalization processing
- C语言ATM自动取款机系统项目的设计与开发
- Strlen introduction, and the difference between sizeof
- Jupyter Notebook安装代码提示功能
- FreeRTOS learning (I)
- HDU 3592 World Exhibition (differential constraint)
- Testcafe's positioning, operation of page elements, and verification of execution results
- Improve the core quality of steam education among students
- alter和confirm,prompt的区别
- Test report don't step on the pit
猜你喜欢

Web渗透之域名(子域名)收集方法

解析智能扫地机器人中蕴含的情感元素

【CPU占用高】software_reporter_tool.exe

Jupyter Notebook安装代码提示功能

01 node express system framework construction (express generator)

Analyze the emotional elements contained in intelligent sweeping robot

字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...
![[idea] check out master invalid path problem](/img/83/d36362ba314177cd6f1f74f3e922cd.png)
[idea] check out master invalid path problem

Improve the core quality of steam education among students

Wang Shuang assembly language detailed learning notes 3: registers (memory access)
随机推荐
Testcafe provides automatic waiting mechanism and live operation mode
When initializing with pyqt5, super() and_ init _ () problems faced by the coordinated use of functions, as well as the corresponding learning and solutions
[Sylar] framework -chapter14 tcpserver module
动态sql和分页
低代码是开发的未来吗?浅谈低代码平台
Jupyter notebook installation code prompt function
(manual) [sqli labs27, 27a] error echo, Boolean blind injection, filtered injection
After easycvr is connected to the national standard equipment, how to solve the problem that the equipment video cannot be played completely?
HDU 3592 World Exhibition (differential constraint)
Special topic of APP performance design and Optimization - poor implementation affecting performance
MySQL partition table transformation
Leetcode 15. sum of three numbers
Warning: file already exists but should not: c:\users\workmai\appdata\local\temp appears when Python packages exe\_ MEI13
How to upgrade a pair of 12.2 RAC(primary) and a pair of 12.2 RAC(dataguard) to 19c
Analysis of the reason why easycvr service can't be started and tips for dealing with easy disk space filling
C语言ATM自动取款机系统项目的设计与开发
Research on the design of robot education in stem course
Redux basic syntax
Leetcode 18. sum of four numbers
欧拉路/欧拉回路