POJ 1034 The dog task(二分图匹配)
http://poj.org/problem?id=1034
题意:

猎人和狗一起出去,狗的速度是猎人的两倍,给出猎人的路径坐标,除了这些坐标外,地图上还有一些有趣的点,而我们的狗,就是要尽量去多的有趣的点。前提是在猎人到达一个点的时候,狗必须也正好到。
思路:
二分图匹配,猎人的路径在一边,有趣的点在另一边,我们就是求一个最大匹配。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std; struct node
{
int x, y;
}; node Bob[], Dog[];
int g[][];
int vis[];
int match[];
int path[];
int n, m; double dis(int x1, int y1, int x2, int y2)
{
return sqrt((double)(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
} int dfs(int x)
{
for (int i = ; i < m; i++)
{
if (g[x][i] && !vis[i])
{
vis[i] = ;
if (match[i]==- || dfs(match[i]))
{
match[i] = x;
return ;
}
}
}
return ;
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n >> m)
{
for (int i = ; i < n; i++)
cin >> Bob[i].x >> Bob[i].y;
for (int i = ; i < m; i++)
cin >> Dog[i].x >> Dog[i].y; memset(g, , sizeof(g));
memset(match, -, sizeof(match)); for (int i = ; i < n - ; i++)
for (int j = ; j < m; j++)
{
double d1 = dis(Bob[i].x, Bob[i].y, Bob[i + ].x, Bob[i + ].y);
double d2 = dis(Bob[i].x, Bob[i].y, Dog[j].x, Dog[j].y);
double d3 = dis(Bob[i + ].x, Bob[i + ].y, Dog[j].x, Dog[j].y);
if (d2 + d3 - * d1 <= )
g[i][j] = ;
}
int ans = ;
for (int i = ; i < n; i++)
{
memset(vis, , sizeof(vis));
if(dfs(i)) ans++;
}
cout << ans + n << endl; memset(path, -, sizeof(path));
for (int i = ; i < m; i++)
{
if (match[i] != -)
path[match[i]] = i;
}
for (int i = ; i < n - ; i++)
{
cout << Bob[i].x << " " << Bob[i].y << " ";
if (path[i] != -)
cout << Dog[path[i]].x << " " << Dog[path[i]].y << " ";
}
cout << Bob[n - ].x << " " << Bob[n - ].y << endl;
}
return ;
}
POJ 1034 The dog task(二分图匹配)的更多相关文章
- poj 1034 The dog task (二分匹配)
The dog task Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2559 Accepted: 1038 Sp ...
- POJ 1719 Shooting Contest(二分图匹配)
POJ 1719 Shooting Contest id=1719" target="_blank" style="">题目链接 题意:给定一个 ...
- 【POJ 3020】Antenna Placement(二分图匹配)
相当于用1*2的板覆盖给定的h*w的格子里的点,求最少的板.可以把格子相邻的分成两个集合,如下图,0为一个集合,1的为一个,也就是(行数+列数)为奇数的是一个集合,为偶数的为另一个集合.1010101 ...
- POJ 2112 Optimal Milking(二分图匹配)
[题目链接] http://poj.org/problem?id=2112 [题目大意] 给出一些挤奶器,每台只能供给M头牛用,牛和挤奶器之间有一定的距离 现在要让每头牛都挤奶,同时最小化牛到挤奶器的 ...
- poj 2112 Optimal Milking (二分图匹配的多重匹配)
Description FJ has moved his K ( <= K <= ) milking machines <= C <= ) cows. A ..K; the c ...
- POJ 1422 Air Raid(二分图匹配最小路径覆盖)
POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
- POJ 2226 Muddy Fields (二分图匹配)
[题目链接] http://poj.org/problem?id=2226 [题目大意] 给出一张图,上面有泥和草地,有泥的地方需要用1*k的木板覆盖, 有草地的地方不希望被覆盖,问在此条件下需要的最 ...
- POJ 1486 Sorting Slides(二分图匹配)
[题目链接] http://poj.org/problem?id=1486 [题目大意] 给出每张幻灯片的上下左右坐标,每张幻灯片的页码一定标在这张幻灯片上, 现在问你有没有办法唯一鉴别出一些幻灯片 ...
- POJ 1486 Sorting Slides【二分图匹配】
题目大意:有n张幻灯片和n个数字,幻灯片放置有重叠,每个数字隶属于一个幻灯片,现在问你能够确定多少数字一定属于某个幻灯片 思路:上次刷过二分图的必须点后这题思路就显然了 做一次二分匹配后将当前匹配的边 ...
随机推荐
- 【BZOJ1787】[Ahoi2008]Meet 紧急集合 LCA
[BZOJ1787][Ahoi2008]Meet 紧急集合 Description Input Output Sample Input 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- ZoomIt v4.5
https://technet.microsoft.com/en-us/sysinternals/bb897434.aspx zoomIt: 演示必备辅助软件 ZoomIt(主页|介绍)是一款非常实用 ...
- shell出现syntax error near unexpected token `<' 解决方法
最新在看一个shell资料时,按照教材,却出现如下错误,不能运行 如下,简单的脚本: #!/bin/bash cat |while read line do echo $line done < ...
- 神兽保佑-代码无BUG
┏┓ ┏┓┏┛┻━━━┛┻┓┃ ┃ ┃ ━ ┃┃ ┳┛ ┗┳ ┃┃ ┃┃ ┻ ┃┃ ┃┗━┓ ┏━┛ ┃ ┃ 神兽保佑 ┃ ┃ 代码无BUG! ┃ ┗━━━┓ ┃ ┣┓ ...
- LoadRunner 11 安装
下载地址:http://www.ddooo.com/softdown/61971.htm#dltab LoadRunner是一款专业级别的应用负载测试工具,它可以模拟上千万用户对企业应用进行真实的负载 ...
- nginx跟tp5无法加载控制器
二. 另外502 bad gateway错误,可能是有PHP中的php-fpm.conf里 “ listen fastcgi_pass /tmp/php-cgi.sock ”跟nginx的conf文 ...
- 170515、mybatis批量操作
//Java代码 public void batchAdd(){ SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession(); Stud ...
- SQL---->数据库表设计思想
数据,一对多: 多的表中加外健约束 数据,多对多: 创建中间表,中间表中有关系对应的外健约束 数据一对一: 主从关系,从表中加外健约束,加唯一约束,加非空约束!!!!! 一张表中-自连接:(理论可以, ...
- oracle goldengate技术架构-简单试验(全)
一 GoldenGate简介 Oracle Golden Gate软件是一种基于日志的结构化数据复制备份软件,它通过解析源 数据库在线日志或归档日志获得数据的增量变化,再将这些变化应用到目标数据库, ...