穩定婚姻匹配

2021-09-19 23:05:56 字數 1254 閱讀 4012

要求按照書中 page 5 的 g-s 演算法寫乙個匹配程式(由男方發起邀請)。

(第一行資料表示 man(woman)的數目 n;接下來的資料中,第乙個 n* n 的資料塊表示 man 的優先列表;另乙個 n*n 的資料塊表示 woman 的優先列表)

5 ---------------------- (man(woman)的數目 n)

2 1 4 5 3 -------------- (第乙個男人的優先列表)

4 2 1 3 5

2 5 3 4 1 -------------- (第三個男人的優先列表)

1 4 3 2 5

2 4 1 5 3

5 1 2 4 3 -------------- (第乙個女人的優先列表)

3 2 4 1 5

2 3 4 5 1

1 5 4 3 2

4 2 5 3 1

男人 1 到 n 的匹配物件,每個數字後邊跟乙個空格,最後輸出乙個\n。

樣例輸入:

52 1 4 5 3

4 2 1 3 5

2 5 3 4 1

1 4 3 2 5

2 4 1 5 3

5 1 2 4 3

3 2 4 1 5

2 3 4 5 1

1 5 4 3 2

4 2 5 3 1

樣例輸出:

測試資料範圍:

2 <= n <= 30

總共13個test cases.

樣例**:

#includeusing namespace std;

class person

void init(int n) }

};int finish(person *man)

return 0;

}bool than(person woman,int m,int m2)//判斷woman女性更喜歡哪乙個男性,如果是m,返回true,反之false

}int main()

for (int i = 0; i < n; i++) }

for (int i = 0; i < n; i++) }

while (finish(man))

else

else}}

} }for (int i = 0; i < n; i++)

cout << endl;

}

穩定婚姻匹配演算法

問題概述 n名男青年和n名女青年參加乙個相親會。經過了解,每名男青年在心目中都對所有女青年作了乙個排序,而每名女青年同樣也對男青年作了排序。問這些男女青年之間怎樣才能進行理想的配對。給出男青年和女青年的偏好矩陣 演算法求解過程 演算法設計 1 根據男性的偏好矩陣來進行遍歷 2 在男性的偏好矩陣中依次...

穩定匹配問題 穩定婚姻演算法設計

include using namespace std bool finish or not int,int bool current male is better int num,int male rank in female,int current,int chasing int main fo...

Hdu1914穩定婚姻匹配

題意 給出 n 個男生,n 個女生,給出他們對異性的喜歡順序,求乙個穩定的婚姻組合。思路 穩定婚姻匹配裸題 include include include typedef long long ll const int inf 0x3f3f3f3f const int maxn 30 using na...