hdoj1435 Stable Match(稳定婚姻问题)
简单稳定婚姻问题。
题目描述不够全面,当距离相同时容量大的优先选择。
稳定婚姻问题不存在无解情况。
#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(稳定婚姻问题)的更多相关文章
- HDU 1522 Marriage is Stable 【稳定婚姻匹配】(模板题)
<题目链接> 题目大意: 给你N个男生和N个女生,并且给出所有男生和女生对其它所有异性的喜欢程度,喜欢程度越高的两个异性越容易配对,现在求出它们之间的稳定匹配. 解题分析: 稳定婚姻问题的 ...
- Marriage is Stable HDU1522 稳定婚姻问题基础
几对男女 给出每个人心中的优先级 进行最合理的匹配 要打印名字的话必须有一个名字数组 英文名用map 稳定婚姻问题: 每次循环遍历所有的男的 每个男的对目前未被拒绝的并且优先级最高的进行预匹配 ...
- 【稳定婚姻问题】【HDU1435】【Stable Match】
2015/7/1 19:48 题意:给一个带权二分图 求稳定匹配 稳定的意义是对于某2个匹配,比如,( a ---- 1) ,(b----2) , 如果 (a,2)<(a,1) 且(2,a)& ...
- 【POJ 3487】 The Stable Marriage Problem (稳定婚姻问题)
The Stable Marriage Problem Description The stable marriage problem consists of matching members o ...
- POJ 3487 The Stable Marriage Problem(稳定婚姻问题 模版题)
Description The stable marriage problem consists of matching members of two different sets according ...
- 【转】稳定婚姻问题(Stable Marriage Problem)
转自http://www.cnblogs.com/drizzlecrj/archive/2008/09/12/1290176.html 稳定婚姻是组合数学里面的一个问题. 问题大概是这样:有一个社团里 ...
- 【HDU1914 The Stable Marriage Problem】稳定婚姻问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1914 题目大意:问题大概是这样:有一个社团里有n个女生和n个男生,每位女生按照她的偏爱程度将男生排序, ...
- 最大团&稳定婚姻系列
[HDU] 1530 Maximum Clique 1435 Stable Match 3585 maximum shortest distance 二分+最大团 1522 Marriage is ...
- hdu1435 稳定婚姻问题
题意: Stable Match Special Judge Problem Description Network 公司的BOSS 说现在他们公司建立的信号发射站和接收站经常出现信号发送接收不稳定的 ...
随机推荐
- Mysql的内存优化
老师 vi mysqld_safe# executing mysqld_safe 后面增加export LD_PRELOAD=/usr/local/lib/libtcmalloc.so 可以做一 ...
- c++11多线程学习笔记之三 condition_variable使用
从windows角度来说,condition_variable类似event. 阻塞等待出发,不过condition_variable可以批量出发. 代码如下: // 1111111.cpp : 定义 ...
- Dice 5 ==> dice 7
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- 2018.06.30 cdq分治
#cdq分治 ##一种奇妙的分治方法 优点:可以顶替复杂的高级数据结构:常数比较小. 缺点:必须离线操作. CDQ分治的基本思想十分简单.如下: 我们要解决一系列问题,包含修改和查询操作,我们将这些问 ...
- BaseAdapter
作者通过Java代码来实现布局,而我习惯通过.xml文件来实现,所以我对程序做了如下修改 MainActivity.java public class MainActivity extends Act ...
- UVa 1639 Candy (数学期望+组合数学+高精度存储)
题意:有两个盒子各有n个糖,每次随机选一个(概率分别为p,1-p),然后吃掉,直到有一次,你打开盒子发现,没糖了! 输入n,p,求另一个盒子里糖的个数的数学期望. 析:先不说这个题多坑,首先要用lon ...
- python 实现排列组合
1.python语言简单.方便,其内部可以快速实现排列组合算法,下面做简单介绍. 2.一个列表数据任意组合 2.1主要是利用自带的库 #_*_ coding:utf-8 _*_ #__author__ ...
- ArcGIS Desktop python Add-in Python 插件的文件结构
如上图所示: 插件文件夹在根目录下有一个config.xml文件,这个文件保存有在向导添加的描述该插件的定制信息. 插件还有一个安装文件夹,这个文件夹的主要功能是存放Python脚本. 你可以在安装文 ...
- 给Notepad++换主题
Notepad++是一款不错的编辑器,很轻巧,我很喜欢它.再换个主题,加个代码高亮,看上去就更专业了.如果你是Mac用户,应该听说或使用过Textmate(什么?没听过,那你该补课了!),Textma ...
- 反编译 轻松调频 Android APP 下载“飞鱼秀”录音
经常听“飞鱼秀”,但是由于时间的原因,只能听回放,但是轻松调频的APP做的有点儿... 听回放的时候经常会中断,还不能拖动进度条,就决定把录音下载下来听. 1.反编译apk(Android反编译过程见 ...