翻译。。。


The Stable Marriage Problem

1000ms 32768K

描述:

The stable marriage problem consists of matching members of two different sets according to the member’s preferences for the other set’s members. The input for our problem consists of:

a set M of n males;
a set F of n females;

for each male and female we have a list of all the members of the opposite gender in order of preference (from the most preferable to the least).
A marriage is a one-to-one mapping between males and females. A marriage is called stable, if there is no pair (m, f) such that f ∈ F prefers m ∈ M to her current partner and m prefers f over his current partner. The stable marriage A is called male-optimal if there is no other stable marriage B, where any male matches a female he prefers more than the one assigned in A.

Given preferable lists of males and females, you must find the male-optimal stable marriage.
 

输入:

The first line gives you the number of tests. The first line of each test case contains integer n (0 < n < 27). Next line describes n male and n female names. Male name is a lowercase letter, female name is an upper-case letter. Then go n lines, that describe preferable lists for males. Next n lines describe preferable lists for females.
 

输出:

For each test case find and print the pairs of the stable marriage, which is male-optimal. The pairs in each test case must be printed in lexicographical order of their male names as shown in sample output. Output an empty line between test cases.

稳定婚姻问题
这个稳定婚姻问题包括根据成员对其他组成员的喜好将两个不同组的成员匹配起来。我们问题的输入包括:
一个有n个男性的M组;
一个有n个女性的F组;
对于每个男性和女性我们有一个表格上面按顺序写着所有不同性别成员的喜好排名(从最喜欢到最不喜欢)。
一个婚姻是男女之间一对一的。如果一对(m,f)不存在它的f ∈ F比她现在的伴侣更喜欢m ∈ M同时m比他现在的伴侣更喜欢f的情况,那么我们就称一个婚姻是稳定的。对于一个稳定的婚姻A,如果没有其他稳定的婚姻B它的男性匹配一个A中男性更喜欢的女性,那么这个稳定的婚姻A被称为男性最佳。
给出男性和女性的喜好列表,你必须找到男性最佳的稳固婚姻。
输入:
第一行给你测试的组数。每组数据的第一行包括一个整数n(0<n<27)。第二行描述n个男性和n个女性的名字。男性名字是一个小写字母,女性名字是一个大写字母。之后n行描述喜好男性的列表。之后n行描述喜好女性的列表。
输出:
对于每个测试组找到并且打出稳定男性最佳的稳定婚姻。每组数据里的这一对必须想下面显示的案例输出一样按他们中男性名字的字典顺序打出。在两个测试组之间打出一行空行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值