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 说现在他们公司建立的信号发射站和接收站经常出现信号发送接收不稳定的 ...
随机推荐
- Java一个文件上传工具类
/** * 文件上传 * * @author cary * @since 2012-12-19 下午2:22:12 */ public class FileUploader { static fina ...
- loadrunner--TPS和平均事务响应时间
TPS就是每秒事务数,但是事务是基于虚拟用户数的,假如1个虚拟用户在1秒内完成1笔事务,那么TPS明显就是1:如果 某笔业务响应时间是1ms,那么1个用户在1秒内能完成1000笔事务,TPS就是100 ...
- 7. Debug on local machine
Step 1:
- 并发编程(三)Promise, Future 和 Callback
并发编程(三)Promise, Future 和 Callback 异步操作的有两个经典接口:Future 和 Promise,其中的 Future 表示一个可能还没有实际完成的异步任务的结果,针对这 ...
- 构造函数constructor 与析构函数destructor(四)
拷贝构造函数:拷贝构造函数就是在用一个类对象来创建另外一个类对象时被调用的构造函数,如果我们没有显示的提供拷贝构造函数,编译器会隐式的提供一个默认拷贝构造函数. 拷贝构造函数的定义是X(const X ...
- 2018.10.20 NOIP模拟 巧克力(trie树+dfs序+树状数组)
传送门 好题啊. 考虑前面的32分,直接维护后缀trietrietrie树就行了. 如果#号不在字符串首? 只需要维护第一个#前面的字符串和最后一个#后面的字符串. 分开用两棵trie树并且维护第一棵 ...
- 2018.09.26 bzoj1015: [JSOI2008]星球大战starwar(并查集)
传送门 并查集经典题目. 传统题都是把删边变成倒着加边,这道题是需要倒着加点. 处理方法是将每个点与其他点的边用一个vector存起来,加点时用并查集统计答案就行了. 代码: #include< ...
- hadoop学习笔记(四):hdfs常用命令
一.hadoop fs 1.创建目录 [root@master hadoop-]# hadoop fs -mkdir /testdir1 [root@master hadoop-]# hadoop f ...
- Unit Testing of Spring MVC Controllers1
我们的pom.xml文件相关的部分看起来如下: <dependency> <groupId>com.fasterxml.jackson.core</groupId& ...
- 使用yum命令报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
背景: yum包的管理是使用python写的,有对应的python版本 遇到的问题报错如下: File "/usr/bin/yum", line 30 except K ...