题意:建立一个匹配表,使得一个发射点对应一个接收点,对于某一个发射点来说,它的接收点离它越近那么就会更稳定,同样对于接收点也是一样的情况。
匹配的目标是使得整个网络变得稳定。
对于某2个匹配,比如,( a ---- 1) ,(b----2) ,如果发射点a 离接收点2 比 1要近,而且2 也离 发射点a要比 b 近,那么 a 就很有可能把信号发到 2中,我们就说这个搭配是不稳定的。
而且每个点都有一个容量值,如果对于一个发射点到2个接收点的距离一样的话,它将首先选择容量大的那个。

题解:稳定婚姻匹配
让发射点一个个去匹配接收点即可。

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int maxn = 205;
int t, n;
struct node {int id, w;double x, y, z;
}s[maxn], r[maxn];  //send  receivedouble dis(node e1, node e2) { return sqrt((e1.x - e2.x) * (e1.x - e2.x) + (e1.y - e2.y) * (e1.y - e2.y) + (e1.z - e2.z) * (e1.z - e2.z)); }
struct fav {int id, w;double val;//fav(int a, int w, double b) :id(a), w(w), val(b) {}
}lover[maxn];
bool cmp(fav x, fav y) { return x.val == y.val ? x.w > y.w : x.val < y.val; }
int boy_love_who[maxn][maxn], girl_love_fir[maxn][maxn];
int boy[maxn], girl[maxn], kth[maxn];
inline void G_S() {for (int i = 1; i <= n; i++) boy[i] = girl[i] = kth[i] = 0;bool flag, no = 0;while (true) {flag = false;for (int i = 1; i <= n; i++) {if (!boy[i]) {int g = boy_love_who[i][++kth[i]];if (kth[i] > n) {no = 1;break;}if (!girl[g]) {girl[g] = i;boy[i] = g;continue;}else if (girl_love_fir[g][i] < girl_love_fir[g][girl[g]]) {boy[girl[g]] = 0;girl[g] = i;boy[i] = g;}flag = true;}}if (no) break;if (!flag) break;}if (no) puts("Impossible");else for (int i = 1; i <= n; i++) printf("%d %d\n", girl[i], i);
}
int main() {scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 1; i <= n; i++) scanf("%d%d%lf%lf%lf", &s[i].id, &s[i].w, &s[i].x, &s[i].y, &s[i].z);for (int i = 1; i <= n; i++) scanf("%d%d%lf%lf%lf", &r[i].id, &r[i].w, &r[i].x, &r[i].y, &r[i].z);for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {lover[j] = { r[j].id, r[j].w, dis(s[i], r[j]) };}sort(lover + 1, lover + n + 1, cmp);for (int j = 1; j <= n; j++) {boy_love_who[i][j] = lover[j].id;}for (int j = 1; j <= n; j++) {lover[j] = { s[j].id, s[j].w, dis(s[j], r[i]) };}sort(lover + 1, lover + n + 1, cmp);for (int j = 1; j <= n; j++) {girl_love_fir[i][lover[j].id] = j;}}G_S();puts("");}return 0;
}

HDU 1435 Stable Match (稳定婚姻匹配)相关推荐

  1. hdu - 1435 Stable Match 稳定婚姻问题、Gale-Shapley算法模板

    稳定婚姻的描述: 假如你是一个媒人,有若干个单身男子登门求助,还有同样多的单身女子也前来征婚.如果你已经知道这些女孩儿在每个男孩儿心目中的排名,以及男孩儿们在每个女孩儿心中的排名,你应该怎样为他们牵线 ...

  2. HDU 1522 Marriage is Stable (稳定婚姻匹配)

    题意:稳定婚姻匹配问题,板子题. 题解:稳定婚姻匹配 还好做了这题,之前的板子有点问题,1435数据太弱了. #define _CRT_SECURE_NO_WARNINGS #include<i ...

  3. Marriage is Stable 【HDU - 1522】【稳定婚姻匹配问题】

    题目链接 什么是婚姻匹配问题呢?我做了这道题后就有了这样的体会 -- 比谁更渣??? 我们知道,有N个男生还有N个女生,要把每个男生和女生匹配起来,让他们结婚,但是呢,有这样的情况,就是假如我们现在B ...

  4. 稳定婚姻匹配(Stable Match, HDOJ 1435, HDOJ 1914, 详解)

    稳定婚姻匹配 HDOJ 1435 Stable Match(此例基于发射点优先的匹配,但题目并未明确表明) Time Limit: 2000/1000 MS (Java/Others) Memory ...

  5. HDU 1914 The Stable Marriage Problem (稳定婚姻匹配)

    题意:稳定婚姻匹配问题,板子题. 题解:稳定婚姻匹配 注意按字典序输出,还有输出格式,最后个样例不输出空行. #define _CRT_SECURE_NO_WARNINGS #include<i ...

  6. SGU 264 Travel(稳定婚姻匹配)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=264 题意:稳定婚姻匹配. 思路:对于每个男的依次从自己最喜欢的女的开始求婚若女的还 ...

  7. Hdu1914稳定婚姻匹配

    题意: 给出 n 个男生,n 个女生,给出他们对异性的喜欢顺序,求一个稳定的婚姻组合. 思路: 稳定婚姻匹配裸题 #include <cstdio> #include <cstrin ...

  8. ALG1:GS算法,稳定婚姻匹配问题

    ALG1:GS算法,稳定婚姻匹配问题 问题描述如下: (详见NKU计算机上机课程辅助评测) 稳定婚姻匹配 实现代码: (此代码逻辑可通过全部测试样例) 由于代码有一段时间了,一下的展示代码是没有自己的 ...

  9. 图论 —— 稳定婚姻问题与延迟认可算法

    [稳定婚姻问题] 1.集合 M 表示 n 个男性 2.集合 F 表示 n 个女性 3.对于每个人我们都按异性的中意程度给出一份名单(从最中意的到最不中意的) 如果没有 ,f 对 m 比对她的配偶中意的 ...

最新文章

  1. 周鸿祎:过去只能在虚拟世界里发起的网络攻击,现在都可以通过物联网直达生产一线...
  2. HDU1533 Going Home(最小费用最大流 spfa模版)
  3. Enterprise Library深入解析与灵活应用(3):倘若将Unity、PIAB、Exception Handling引入MVP模式.. .. .....
  4. ElasticSearch 2.2 升级 6.2.4
  5. mysql slave是什么_创建slave的搜索结果-阿里云开发者社区
  6. GDCM:gdcm::Reader的测试程序
  7. 事物 @Transactional
  8. java list详解_Java 中 list 用法案例详解
  9. Javascript面向对象编程(一):对象的产生
  10. 一文学会 SSH 服务!
  11. 吴陆 java,成年人的世界,崩溃无声。
  12. TypeError: float() argument must be a string or a number, not 'datetime.date'
  13. 小米笔记本pro lol测试软件,小米笔记本Pro游戏实测,MX150显卡竟有猫腻
  14. cmd 环境下载文件的几种方法
  15. 高级终端termux下载不了Python_基于Termux打造Android手机渗透工具
  16. 【neo4j】知识图谱实战---构建红楼梦知识图谱
  17. onenote使用python开发_我应该用onenote还是印象笔记?
  18. 微信公众号的号内搜索关键词怎么设置 号内搜索关键词删除和排序方法
  19. Google搜索技巧语法
  20. IO summery

热门文章

  1. Forest 使用简介
  2. matlab 声明变量范围,matlab中syms如何定义变量范围
  3. 【零信任落地案例】指掌易某集团灵犀・SDP零信任解决方案
  4. 抓住机遇 扶摇直上三千尺:中国企业软件的大风口
  5. android 禁用通知栏_如何在Android上禁用通知
  6. 输入法画面_百度输入法出3D“弹幕式”,我与大师的距离打破了一屏之隔
  7. golang分词工具sego的使用
  8. 【Tools】PolyWorks MS 2020软件安装详解(加密狗版)
  9. 【传感器】入侵检测系统(uart、CC2530、误触关闭)
  10. 在Ubuntu18.04上搭建私有网盘 —— ownCloud