大意略。

二分图最佳匹配,KM算法。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;const int maxn = 110;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;struct node
{double x, y;node(double x=0, double y=0): x(x), y(y) {}
}A[maxn], B[maxn];double sqr(double x) { return x*x; }
double dcmp(double x) { if(fabs(x) < eps) return 0; else return x < 0? -1:1; }
double Dist(node a, node b) { return sqrt(sqr(a.x-b.x) + sqr(a.y-b.y)); }int n;double W[maxn][maxn];
double Lx[maxn], Ly[maxn];int Left[maxn];
bool S[maxn], T[maxn];bool match(int i)
{S[i] = 1;for(int j = 1; j <= n; j++) if(!dcmp(Lx[i]+Ly[j]-W[i][j])&& !T[j]){T[j] = 1;if(!Left[j] || match(Left[j])){Left[j] = i;return 1;}}return 0;
}void update()
{double a = INF;for(int i = 1; i <= n; i++) if(S[i])for(int j = 1; j <= n; j++) if(!T[j])a = min(a, Lx[i]+Ly[j]-W[i][j]);for(int i = 1; i <= n; i++){if(S[i]) Lx[i] -= a;if(T[i]) Ly[i] += a;}
}void KM()
{for(int i = 1; i <= n; i++){Left[i] = Lx[i] = Ly[i] = 0;for(int j = 1; j <= n; j++)Lx[i] = max(Lx[i], W[i][j]);}for(int i = 1; i <= n; i++){for(;;){for(int j = 1; j <= n; j++) S[j] = T[j] = 0;if(match(i)) break; else update();}}
}void read_case()
{for(int i = 1; i <= n; i++){double x, y;scanf("%lf%lf", &x, &y);A[i] = node(x, y);}for(int i = 1; i <= n; i++){double x, y;scanf("%lf%lf", &x, &y);B[i] = node(x, y);}
}void build()
{for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++){W[j][i] = -Dist(A[i], B[j]);}
}void solve()
{read_case();build();KM();for(int i = 1; i <= n; i++) printf("%d\n", Left[i]);
}int main()
{int times = 0;while(~scanf("%d", &n)){if(++times > 1) printf("\n");solve();}return 0;
}

LA 4043 Ants相关推荐

  1. LA 4043 Ants 二分图完美匹配

    题目: https://icpcarchive.ecs.baylor.edu/external/40/4043.pdf 样例运行结果与sample output不一样,坑死了. const int I ...

  2. UVALive 4043 Ants(最大权匹配)

    题目链接: UVALive 4043 Ants 题意: 给出平面上n个白点和n个黑点的点坐标,将这n个白点和n个黑点用n条不相交的线段连接,输出每个白点连接的黑点的编号. n<=100. 分析: ...

  3. UVALive 4043 Ants

    KM   构图求最小权值匹配 保证最小的权值,所连的边一定是能够不相交的. Ants Time Limit: 3000MS   Memory Limit: Unknown   64bit IO For ...

  4. Uvalive 4043 - Ants(二分图完美匹配)

    题目链接 https://vjudge.net/problem/UVALive-4043 [题意]        给出n个白点和n个黑点的坐标,要求用n条不相交的线段把它们连起来,其中每条线段恰好连接 ...

  5. 训练指南 UVALive - 4043(二分图匹配 + KM算法)

    layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...

  6. WCDMA中的URA和LA/RA

    1.关于URA的概念: URA(UTRAN Registration Area)是UTRAN内部区域的划分适用于UE处于RRC连接状态的情形,而且只能在UTRAN端使用(比如由UTRAN发起的寻呼). ...

  7. LA 5717枚举+最小生成树回路性质

    1 /*LA 5717 2 <训练指南>P343 3 最小生成树的回路性质 4 在生成的最小生成树上,新增一条边e(u,v) 5 若原图上u到v的路径的最大边大于e,则删除此边,加上e,否 ...

  8. 编译php时错误make ***[libphp5.la] Error 1

    错误信息 make ***[libphp5.la] Error 1 /usr/bin/ld: cannot find -lltdl collect2: ld returned 1 exit statu ...

  9. 获取长度length_lab、labE、la、laE、ll、llE 钢筋锚固搭接长度6项参数的相互关系...

    文|施工小诸葛 目录 01   相关概念 02   字母含义 03   lab 非抗震纵向受拉钢筋的基本锚固长度 04   la 非抗震纵向受拉钢筋的锚固长度 05   ll 非抗震纵向受拉钢筋搭接长 ...

最新文章

  1. 元素 “aop:aspectj-autoproxy” 的前缀 “aop” 未绑定
  2. jquery 移除border_jQuery - 删除元素
  3. 富有客户端技术之——jQuery EasyUI
  4. [java]OutOfMemoryError 原因及解决办法
  5. 使用轮转算法求时间片_彩票调度算法,让进程们拼手气? --当操作系统遇上随机算法...
  6. 用贝叶斯来看看抛硬币的概率
  7. android集成测试工具,android – 集成测试和Cucumber测试
  8. 关于iPhone 11系列、A13芯片 知乎网友是这么说的
  9. Django 视图层
  10. python工资高还是java-python为什么叫爬虫 python工资高还是java的高
  11. [codeup 2143] 迷瘴
  12. Android:什么是签名、为什么要给应用程序签名、如何给应用程序签名
  13. 关于笔记本电脑网卡出问题的简单解决
  14. TMS320F280049C 串行通信接口Serial Communications Interface (SCI)之RS485通信(多摩川编码器)
  15. 原码一位乘法和补码一位乘法
  16. 苹果手机怎么无线投屏?苹果手机无线投屏到电脑
  17. Unity Rect.OverLaps(Rect other) 改进
  18. 倾斜模型精细化处理_浅谈几个倾斜摄影三维模型的修补软件 - 纳金网
  19. java vardump_Java内存查看与分析
  20. Tomcat单机多实例配置

热门文章

  1. Planting Trees Day 植树节 一起去种树
  2. 配准带尺度点云的方法汇总
  3. 全新整理:微软、谷歌、百度等公司经典面试100题[第101-160题]
  4. ARM裸机-13.LCD
  5. 湖南中医药大学成考2022年下学期网络课程学习与考试工作安排
  6. 用vlookup在excel表格里查找数据
  7. 大文件数据恢复-轻松恢复大于4GB的文件
  8. 高维统计理论 Gauss与Rademacher复杂度
  9. 【疲劳检测】基于形态学实现疲劳检测附matlab代码
  10. 爱酱,鹿鸣?!自己怎么做一个虚拟二次元偶像?