简单稳定婚姻问题。

题目描述不够全面,当距离相同时容量大的优先选择。

稳定婚姻问题不存在无解情况。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 205
using namespace std;
struct point{
int num,v;
double x,y,z;
}Man_array[maxn],Woman_array[maxn];
struct point2{
int num,v;
double dis;
}A[maxn*maxn];
int n;
int nowb[maxn],nowg[maxn],V[maxn][maxn],B_g[maxn][maxn],G_b[maxn][maxn];
double calc(point p,point q){
double xx=p.x-q.x,yy=p.y-q.y,zz=p.z-q.z;
return sqrt(xx*xx+yy*yy+zz*zz);
}
int comp(point2 p,point2 q){
return p.dis<q.dis || p.dis==q.dis && p.v>q.v;
}
void Stable_Marriage(){
memset(V,,sizeof(V));memset(nowb,-,sizeof(nowb));memset(nowg,-,sizeof(nowg));
queue<int> Q;
for (int i=;i<n;i++) Q.push(i);
while (!Q.empty()){
int pre=Q.front(),res;
Q.pop();
for (int i=;i<n;i++){
int res=B_g[pre][i];
if (V[pre][res]) continue;
V[pre][res]=;
if (nowg[res]==-){
nowg[res]=pre;
nowb[pre]=res;
break;
}
else if (G_b[res][nowg[res]]<G_b[res][pre]){
Q.push(nowg[res]);
nowg[res]=pre;
nowb[pre]=res;
break;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie();cout.tie();
int t;
cin >> t;
while (t--){
cin >> n;
for (int i=;i<n;i++){
cin >> Man_array[i].num >> Man_array[i].v >> Man_array[i].x >> Man_array[i].y >> Man_array[i].z;
}
for (int i=;i<n;i++){
cin >> Woman_array[i].num >> Woman_array[i].v >> Woman_array[i].x >> Woman_array[i].y >> Woman_array[i].z;
}
//男——女
for (int i=;i<n;i++){
for (int j=;j<n;j++){
A[j].dis=calc(Man_array[i],Woman_array[j]);
A[j].v=Woman_array[j].v;
A[j].num=j;
}
sort(A,A+n,comp);
for (int j=;j<n;j++) B_g[i][j]=A[j].num;
}
//女——男
for (int i=;i<n;i++){
for (int j=;j<n;j++){
A[j].dis=calc(Woman_array[i],Man_array[j]);
A[j].v=Man_array[j].v;
A[j].num=j;
}
sort(A,A+n,comp);
for (int j=;j<n;j++) G_b[i][A[j].num]=n-j+;
}
Stable_Marriage();
for (int i=;i<n;i++){
cout << Man_array[i].num << " " << Woman_array[nowb[i]].num << endl;
}
cout << endl;
}
return ;
}

hdoj1435 Stable Match(稳定婚姻问题)的更多相关文章

  1. HDU 1522 Marriage is Stable 【稳定婚姻匹配】(模板题)

    <题目链接> 题目大意: 给你N个男生和N个女生,并且给出所有男生和女生对其它所有异性的喜欢程度,喜欢程度越高的两个异性越容易配对,现在求出它们之间的稳定匹配. 解题分析: 稳定婚姻问题的 ...

  2. Marriage is Stable HDU1522 稳定婚姻问题基础

    几对男女   给出每个人心中的优先级   进行最合理的匹配 要打印名字的话必须有一个名字数组 英文名用map 稳定婚姻问题: 每次循环遍历所有的男的 每个男的对目前未被拒绝的并且优先级最高的进行预匹配 ...

  3. 【稳定婚姻问题】【HDU1435】【Stable Match】

    2015/7/1 19:48 题意:给一个带权二分图  求稳定匹配 稳定的意义是对于某2个匹配,比如,( a ---- 1) ,(b----2) , 如果 (a,2)<(a,1) 且(2,a)& ...

  4. 【POJ 3487】 The Stable Marriage Problem (稳定婚姻问题)

    The Stable Marriage Problem   Description The stable marriage problem consists of matching members o ...

  5. POJ 3487 The Stable Marriage Problem(稳定婚姻问题 模版题)

    Description The stable marriage problem consists of matching members of two different sets according ...

  6. 【转】稳定婚姻问题(Stable Marriage Problem)

    转自http://www.cnblogs.com/drizzlecrj/archive/2008/09/12/1290176.html 稳定婚姻是组合数学里面的一个问题. 问题大概是这样:有一个社团里 ...

  7. 【HDU1914 The Stable Marriage Problem】稳定婚姻问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1914 题目大意:问题大概是这样:有一个社团里有n个女生和n个男生,每位女生按照她的偏爱程度将男生排序, ...

  8. 最大团&稳定婚姻系列

    [HDU]   1530 Maximum Clique 1435 Stable Match 3585 maximum shortest distance 二分+最大团 1522 Marriage is ...

  9. hdu1435 稳定婚姻问题

    题意: Stable Match Special Judge Problem Description Network 公司的BOSS 说现在他们公司建立的信号发射站和接收站经常出现信号发送接收不稳定的 ...

随机推荐

  1. linux下安装oracle数据库详细教程

    一.安装yum源 下载或拷贝RedHat的iso镜像到本地,比如 /repo/iso/ rhel-server-6.6-x86_64-dvd.iso 1.建立ISO文件存放目录(/repo/iso)和 ...

  2. BZOJ1106[POI2007]立方体大作战tet - 树状数组

    描述 一个叫做立方体大作战的游戏风靡整个Byteotia.这个游戏的规则是相当复杂的,所以我们只介绍他的简单规则:给定玩家一个有2n个元素的栈,元素一个叠一个地放置.这些元素拥有n个不同的编号,每个编 ...

  3. Ubuntu 制作离线安装包

    2017-04-07 11:39:59 一.应用场景 Ubuntu在不能上网情况下,又需要安装软件或更新系统 二.离线安装包制作 在一台能正常上网的Ubuntu系统上,安装需要的软件包 $sudo a ...

  4. 2018.08.29 NOIP模拟 table(拓扑排序+建图优化)

    [描述] 给出一个表格,N 行 M 列,每个格子有一个整数,有些格子是空的.现在需要你 来做出一些调整,使得每行都是非降序的.这个调整只能是整列的移动. [输入] 第一行两个正整数 N 和 M. 接下 ...

  5. 第九章:叹词(L'interjection )

    ➊叹词的使用词类 .拟声词.如:    Ah !啊!呀!哎!      Hein  !嗯!呣!哎!    Paf  !啪!叭!             Pouf  !扑通(重物坠地声)    Euh ...

  6. Netty学习第四节WebSocket入门

    1.什么是webSocket?       webSocket是H5提出的一个协议规范,webSocket约定了一个通信的规范,通过一个握手的机制,客户端和服务端,就能建立一个类似TCP的连接,从而方 ...

  7. UVa 1639 Candy (数学期望+组合数学+高精度存储)

    题意:有两个盒子各有n个糖,每次随机选一个(概率分别为p,1-p),然后吃掉,直到有一次,你打开盒子发现,没糖了! 输入n,p,求另一个盒子里糖的个数的数学期望. 析:先不说这个题多坑,首先要用lon ...

  8. 继承方法-->call继承

    function Person(name,age,sex){ this.name = name; this.age = age; this.sex = sex; }function P1(name,a ...

  9. Shiro 登录页面的几个固定字段

    http://shiro.apache.org/webapp-tutorial.html Step 3b: Add a login page Since Step 3a enabled login a ...

  10. xib创建cell的两种方法

    方法一:第一步:[self.collectionView registerNib:[UINib nibWithNibName:@"QGLShareBtnCell" bundle:n ...