https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1990

题目大意:

在盛大的校园舞会上有n位男生和n位女生,每人都对每个异性有一个排序,代表对他们的喜欢程度。你的任务是将男生和女生一一配对,使得男生U和女生V不存在一下情况1.男生u和女生v不是舞伴2,他们喜欢对方的程度都大于各自当前舞伴的程度。如果出现了2中的情况,他们可能擅自抛下自己的舞伴,另外组成一对。

你的任务是对于每个女生,在所有可能和她跳舞的男生中,找出她最喜欢的那一个。

思路:

看图。。。。

刘汝佳书上的原题。。划线的部分我只是想表明这个算法的。。。。丧失。。。。

稳定婚姻问题,求婚拒绝算法的实现。。。我觉得我也丧心病狂了。。。。。。情人节就是要做这种。。。。。

  1. #include<cstdio>
  2. #include<queue>
  3. #include<cstring>
  4. using namespace std;
  5. const int MAXN=1000+10;
  6. int future_wife[MAXN],future_husband[MAXN];
  7. int order_man[MAXN][MAXN],order_woman[MAXN][MAXN],next_persue[MAXN];
  8. queue<int> q; //为订婚男士排队中。。。
  9. void engage(int man,int woman) //订婚
  10. {
  11. int getout=future_husband[woman]; //这个可怜的男人被抛弃了。当然可能为0,就是没有这个人
  12. if(getout!=0)
  13. {
  14. q.push(getout); //兄弟,你得重新找别人了。。
  15. future_wife[getout]=0; //抛弃现任未婚夫
  16. }
  17. future_husband[woman]=man;
  18. future_wife[man]=woman;
  19. }
  20. int main()
  21. {
  22. int T;
  23. scanf("%d",&T);
  24. while(T--)
  25. {
  26. while(!q.empty())
  27. q.pop();
  28.  
  29. int n;
  30. scanf("%d",&n);
  31. for(int i=1;i<=n;i++)
  32. {
  33. for(int j=1;j<=n;j++)
  34. scanf("%d",&order_man[i][j]); //编号为i的男士第j个喜欢的人。
  35. future_wife[i]=0; //接下来应该向排名为1的女士求婚。
  36. next_persue[i]=1; //没有未婚妻。
  37. q.push(i);
  38. }
  39.  
  40. for(int i=1;i<=n;i++)
  41. {
  42. for(int j=1;j<=n;j++)
  43. {
  44. int temp;
  45. scanf("%d",&temp);
  46. order_woman[i][temp]=j; //在编号为i的女士心目中,编号为temp的男士排名
  47. }
  48. future_husband[i]=0; //没有未婚夫
  49. }
  50. while(!q.empty())
  51. {
  52. int man=q.front(); //该这个男的求婚了!
  53. q.pop();
  54. int woman=order_man[man][next_persue[man]++]; //下一个求婚对象
  55. if(future_husband[woman]==0) //如果女士没有对象,直接订婚
  56. engage(man,woman);
  57. else if(order_woman[woman][man]<order_woman[woman][ future_husband[woman] ])
  58. engage(man,woman); //由于好感度高于现在女士的未婚夫,所以抢亲成功。
  59. else
  60. q.push(man); //直接被拒绝,下次再来。
  61. }
  62. for(int i=1;i<=n;i++) printf("%d\n",future_wife[i]);
  63. if(T) printf("\n");
  64. }
  65. return 0;
  66. }

LA 3989 - Ladies' Choice 稳定婚姻问题的更多相关文章

  1. UVA 1175 Ladies' Choice 稳定婚姻问题

    题目链接: 题目 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题 ...

  2. UVALive3989 Ladies' Choice —— 稳定婚姻问题 Gale - Shapely算法

    题目链接:https://vjudge.net/problem/UVALive-3989 题解: 题意:有n个男生和n个女生.每个女生对男神都有个好感度排行,同时每个男生对每个女生也有一个好感度排行. ...

  3. UVALive 3989 Ladies' Choice

    Ladies' Choice Time Limit: 6000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...

  4. UVALive 3989 Ladies' Choice(稳定婚姻问题:稳定匹配、合作博弈)

    题意:男女各n人,进行婚配,对于每个人来说,所有异性都存在优先次序,即最喜欢某人,其次喜欢某人...输出一个稳定婚配方案.所谓稳定,就是指未结婚的一对异性,彼此喜欢对方的程度都胜过自己的另一半,那么这 ...

  5. UVALive 3989Ladies' Choice(稳定婚姻问题)

    题目链接 题意:n个男生和女生,先是n行n个数,表示每一个女生对男生的好感值排序,然后是n行n列式每一个男生的好感值排序,输出N行,即每个女生在最好情况下的男生的编号 分析:如果是求女生的最好情况下, ...

  6. UVALive 3989 Ladies&#39; Choice

    经典的稳定婚姻匹配问题 UVALive - 3989 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format:  ...

  7. Ladies' Choice UVALive - 3989 稳定婚姻问题 gale_shapley算法

    /** 题目: Ladies' Choice UVALive - 3989 链接:https://vjudge.net/problem/UVALive-3989 题意:稳定婚姻问题 思路: gale_ ...

  8. 【UVAlive 3989】 Ladies' Choice (稳定婚姻问题)

    Ladies' Choice Teenagers from the local high school have asked you to help them with the organizatio ...

  9. UVALive-3989 Ladies' Choice (稳定婚姻问题)

    题目大意:稳定婚姻问题.... 题目分析:模板题. 代码如下: # include<iostream> # include<cstdio> # include<queue ...

随机推荐

  1. sed的一些tricks

    1.sed -f xx.sed input_file 可以将一系列操作放在一个xx.sed脚本里执行 ``` #!/bin/sed -f ``` 2.在匹配字符串后面或行尾添加内容 在text后面添加 ...

  2. openssl之BIO系列之25---结束语

    (作者:DragonKing, Mail: wzhah@263.net ,公布于:http://openssl.126.com之ope nssl专业论坛) 经过半个月左右,最终将BIO的结构和各个分支 ...

  3. css中linear-gradient的使用

    注明:此篇文章来自http://www.cnblogs.com/lhb25/archive/2013/01/30/css3-text-shadow.html.

  4. 洛谷P2891 [USACO07OPEN]吃饭Dining

    题目描述 Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she w ...

  5. Java(标识符,关键字,注释,常量,变量)

    标识符 在java程序中有些名字是可以自定义的,那么这些自定义的名字我们就称作为自定义的标识符. 标识符要注意的细节: 标识符的组成元素是由字母(a-zA-Z).数字(0-9).下划线(_).美元符号 ...

  6. spring三大框架整合

        Spring概述 Spring介绍 Spring它是一个一站式的分层轻量级框架. Spring体系结构 1.      core container a)        beans与core ...

  7. 【习题 8-10 UVA - 1614】Hell on the Markets

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 证明:前i个数一定能凑够1..sum[i]中的所有数字 i=1时显然成立. 现在假设i>=2时结论成立 即前i个数字能凑出1. ...

  8. [Angular & Unit Testing] Testing a RouterOutlet component

    The way to test router componet needs a little bit setup, first we need to create a "router-stu ...

  9. 论Node在构建超媒体API中的作用

    论Node在构建超媒体API中的作用 作者:chszs,转载需注明. 博客主页:http://blog.csdn.net/chszs 超媒体即Hypermedia,是一种採用非线性网状结构对块状多媒体 ...

  10. LinearLayout-控件不显示

    今天Mms遇到了一个问题,布局如下             <RelativeLayout                android:layout_width="match_par ...