LA 4043 Ants
大意略。
二分图最佳匹配,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相关推荐
- LA 4043 Ants 二分图完美匹配
题目: https://icpcarchive.ecs.baylor.edu/external/40/4043.pdf 样例运行结果与sample output不一样,坑死了. const int I ...
- UVALive 4043 Ants(最大权匹配)
题目链接: UVALive 4043 Ants 题意: 给出平面上n个白点和n个黑点的点坐标,将这n个白点和n个黑点用n条不相交的线段连接,输出每个白点连接的黑点的编号. n<=100. 分析: ...
- UVALive 4043 Ants
KM 构图求最小权值匹配 保证最小的权值,所连的边一定是能够不相交的. Ants Time Limit: 3000MS Memory Limit: Unknown 64bit IO For ...
- Uvalive 4043 - Ants(二分图完美匹配)
题目链接 https://vjudge.net/problem/UVALive-4043 [题意] 给出n个白点和n个黑点的坐标,要求用n条不相交的线段把它们连起来,其中每条线段恰好连接 ...
- 训练指南 UVALive - 4043(二分图匹配 + KM算法)
layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...
- WCDMA中的URA和LA/RA
1.关于URA的概念: URA(UTRAN Registration Area)是UTRAN内部区域的划分适用于UE处于RRC连接状态的情形,而且只能在UTRAN端使用(比如由UTRAN发起的寻呼). ...
- LA 5717枚举+最小生成树回路性质
1 /*LA 5717 2 <训练指南>P343 3 最小生成树的回路性质 4 在生成的最小生成树上,新增一条边e(u,v) 5 若原图上u到v的路径的最大边大于e,则删除此边,加上e,否 ...
- 编译php时错误make ***[libphp5.la] Error 1
错误信息 make ***[libphp5.la] Error 1 /usr/bin/ld: cannot find -lltdl collect2: ld returned 1 exit statu ...
- 获取长度length_lab、labE、la、laE、ll、llE 钢筋锚固搭接长度6项参数的相互关系...
文|施工小诸葛 目录 01 相关概念 02 字母含义 03 lab 非抗震纵向受拉钢筋的基本锚固长度 04 la 非抗震纵向受拉钢筋的锚固长度 05 ll 非抗震纵向受拉钢筋搭接长 ...
最新文章
- 元素 “aop:aspectj-autoproxy” 的前缀 “aop” 未绑定
- jquery 移除border_jQuery - 删除元素
- 富有客户端技术之——jQuery EasyUI
- [java]OutOfMemoryError 原因及解决办法
- 使用轮转算法求时间片_彩票调度算法,让进程们拼手气? --当操作系统遇上随机算法...
- 用贝叶斯来看看抛硬币的概率
- android集成测试工具,android – 集成测试和Cucumber测试
- 关于iPhone 11系列、A13芯片 知乎网友是这么说的
- Django 视图层
- python工资高还是java-python为什么叫爬虫 python工资高还是java的高
- [codeup 2143] 迷瘴
- Android:什么是签名、为什么要给应用程序签名、如何给应用程序签名
- 关于笔记本电脑网卡出问题的简单解决
- TMS320F280049C 串行通信接口Serial Communications Interface (SCI)之RS485通信(多摩川编码器)
- 原码一位乘法和补码一位乘法
- 苹果手机怎么无线投屏?苹果手机无线投屏到电脑
- Unity Rect.OverLaps(Rect other) 改进
- 倾斜模型精细化处理_浅谈几个倾斜摄影三维模型的修补软件 - 纳金网
- java vardump_Java内存查看与分析
- Tomcat单机多实例配置