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 说现在他们公司建立的信号发射站和接收站经常出现信号发送接收不稳定的 ...
随机推荐
- Django之ORM数据库
5.1 数据库的配置 1 django默认支持sqlite,mysql, oracle,postgresql数据库. <1> sqlite django默认使用sqlite的数据库 ...
- 品味性能之道<五>:SQL分析工具
一.SQL语句到底是怎么执行的? 想了解SQL语句到底是怎么执行的,那就需要进行SQL语句执行计划分析. 那什么是SQL语句执行计划呢? 就是Oracle服务器执行SQL语句的过程.例如确定是否使用索 ...
- UI设计是青春饭?今天告诉你真相!
最近有学员来问,“我想转行学习UI设计,但是听很多人说,UI设计是吃青春饭的,互联网公司是不是只选择年轻的血液而淘汰年纪大的?”今天,我来统一回答一下. UI设计是不是青春饭? 我们先来思考一个问题: ...
- 史上最全的Android开发学习教程集锦【初学者】
根据Google的报告,截止2017年5月为止,Android活跃用户已超过20亿,并还在持续增长中.Android系统在几个主要的市场上已超过了iOS系统,特别是在美国,欧洲和日本,然而苹果确实在中 ...
- 2018.10.20 NOIP模拟 巧克力(trie树+dfs序+树状数组)
传送门 好题啊. 考虑前面的32分,直接维护后缀trietrietrie树就行了. 如果#号不在字符串首? 只需要维护第一个#前面的字符串和最后一个#后面的字符串. 分开用两棵trie树并且维护第一棵 ...
- 2018.09.19 atcoder Snuke's Subway Trip(最短路)
传送门 就是一个另类最短路啊. 利用颜色判断当前节点的最小花费的前驱边中有没有跟当前的边颜色相同的. 如果有这条边费用为0,否则费用为1. 这样跑出来就能ac了. 代码: #include<bi ...
- 2018.07.12 atcoder Go Home(贪心)
传送门 题意简述:大家在数轴上生活,公司在 s. 班车送所有人回家,有 n 个住处,第 i 个位置在 xi,居住了 pi 的人. 保证 xi 互不相同. 大家⼀起投票向前还是向后,如果票数相同就固定向 ...
- hdu-1087(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 思路:每确定一个数,后面一个数肯定比它大.所以可以先从最后一个数开始,不断向前确定前面的状态,推 ...
- Windows 下安装mysql总结
1.配置环境变量 将安装目录添加到系统路径 我的电脑->属性->高级->环境变量->path 2.修改my.ini 位于解压安装目录下 在其中修改或添加配置: [mysqld] ...
- fortran write格式
advance="no",就是输出不换行. write(*,"(f10.1)",advance="no")A 格式化输出的控制字符非常的丰富 ...