poj 1034 The dog task (二分匹配)
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 2559 | Accepted: 1038 | Special Judge | ||
Description
Ralph walks on his own way but always meets his master at the specified N points. The dog starts his journey simultaneously with Bob at the point (X1, Y1) and finishes it also simultaneously with Bob at the point (XN, YN).
Ralph can travel at a speed that is up to two times greater than his master's speed. While Bob travels in a straight line from one point to another the cheerful dog seeks trees, bushes, hummocks and all other kinds of interesting places of the local landscape which are specified by M pairs of integers (Xj',Yj'). However, after leaving his master at the point (Xi, Yi) (where 1 <= i < N) the dog visits at most one interesting place before meeting his master again at the point (Xi+1, Yi+1).
Your task is to find the dog's route, which meets the above requirements and allows him to visit the maximal possible number of interesting places. The answer should be presented as a polygonal line that represents Ralph's route. The vertices of this route should be all points (Xi, Yi) and the maximal number of interesting places (Xj',Yj'). The latter should be visited (i.e. listed in the route description) at most once.
An example of Bob's route (solid line), a set of interesting places (dots) and one of the best Ralph's routes (dotted line) are presented in the following picture:

Input
All points in the input file are different and their coordinates are integers not greater than 1000 by the absolute value.
Output
Sample Input
4 5
1 4 5 7 5 2 -2 4
-4 -2 3 9 1 2 -1 3 8 -3
Sample Output
6
1 4 3 9 5 7 5 2 1 2 -2 4
Source
//204K 32MS C++ 1612B 2013-11-11 09:07:25
/* 题意:
有n个点,Bob要按序逐个走过,它的狗的速度最大时他的两倍,每次在两点间他的狗都可以
去浏览一个有趣的点并回到Bob身边,问他的狗最多可以浏览多少个有趣的点,并输出狗经过的点 二分匹配:
Bob要走的点看成是二分中的一个集合,有趣的点看成是二分的另一集合,很明显构图时要符合
有趣点到一条Bob必经路径两点的距离和 小于等于 2*该路径长度时,路径和该有趣的点联通,构好
图后直接匈牙利模板 */
#include<stdio.h>
#include<string.h>
#include<math.h>
struct node{
double x,y;
}p[],q[];
int g[][];
int match[];
int vis[];
int n,m;
double L(node a,node b) //求两点距离
{
return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));
}
void build()
{
memset(g,,sizeof(g));
for(int i=;i<n-;i++){
double l=L(p[i],p[i+]);
for(int j=;j<m;j++)
if(L(p[i],q[j])+L(p[i+],q[j])<=*l) //条件
g[i][j]=;
}
}
int dfs(int x)
{
for(int i=;i<m;i++){
if(!vis[i] && g[x][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return ;
}
}
}
return ;
}
void hungary()
{
memset(match,-,sizeof(match));
int ret=;
for(int i=;i<n-;i++){
memset(vis,,sizeof(vis));
if(dfs(i)) ret++;
}
printf("%d\n",ret+n);
int flag[][]={}; //第二维保存的是必经点中哪个点后有有趣的点和该有趣的点的下标
for(int i=;i<m;i++)
if(match[i]!=-){
flag[match[i]][]=;
flag[match[i]][]=i;
}
for(int i=;i<n-;i++){ //输出
printf("%.0lf %.0lf ",p[i].x,p[i].y);
if(flag[i][]){
printf("%.0lf %.0lf ",q[flag[i][]].x,q[flag[i][]].y);
}
}
printf("%.0lf %.0lf\n",p[n-].x,p[n-].y);
}
int main(void)
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
for(int i=;i<m;i++)
scanf("%lf%lf",&q[i].x,&q[i].y);
build();
hungary();
}
return ;
}
poj 1034 The dog task (二分匹配)的更多相关文章
- POJ 1034 The dog task(二分图匹配)
http://poj.org/problem?id=1034 题意: 猎人和狗一起出去,狗的速度是猎人的两倍,给出猎人的路径坐标,除了这些坐标外,地图上还有一些有趣的点,而我们的狗,就是要尽量去多的有 ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- TTTTTTTTTTTTTTTTT POJ 2226 草地覆木板 二分匹配 建图
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9754 Accepted: 3618 Desc ...
- TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想
Purifying Machine Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5004 Accepted: 1444 ...
- POJ 1466 大学谈恋爱 二分匹配变形 最大独立集
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 11694 Accepted: 5230 D ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...
- poj 1274 The Prefect Stall - 二分匹配
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22736 Accepted: 10144 Description Far ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
随机推荐
- 初学Splunk
splunk简介 https://www.splunk.com/zh-hans_cn/download.html splunk 简体中文版手册 http://docs.splunk.com/Docum ...
- javascript--BOM的onload事件和onunload事件
1.onload事件 onload,页面加载后执行,所谓页面加载完成,指页面上所有的元素创建完毕,引用的所有的外部资源(js.css.图片)等下载完毕. 所以onload执行的比较晚,因为如果页面上有 ...
- Angular : 基础语句说明, 响应式表单指令, 组件生命周期钩子
- yii 自带RBAC
common:中加 'authManager' => [ 'class' => 'yii\rbac\DbManager', 'itemTable' => 'auth_item', ' ...
- Chrome浏览器调试移动端网页 chrome://inspect/#devices
我使用的是魅族(魅蓝NOTE6 ),电脑是win 7系统,以下几步就可以轻松使用浏览器内置的功能调试移动端网页了: 注意:谷歌浏览器需要先FQ,不然调试页面会空白或者报404错误,(不会FQ的可以联系 ...
- Hadoop(21)-数据清洗(ELT)简单版
有一个诸如这样的log日志 去除长度不合法,并且状态码不正确的记录 LogBean package com.nty.elt; /** * author nty * date time 2018-12- ...
- SSH远程登录和端口转发详解
SSH远程登录和端口转发详解 介绍 SSH 是创建在应用层和传输层基础上的安全协议,为计算机上的 Shell(壳层)提供安全的传输和使用环境. SSH 只是协议,有多种实现方式,本文基于其开源实 ...
- 001---Linux系统的启动过程
Linux系统的启动过程 按下电源 开机自检(BIOS):检查cpu.内存.硬盘是否有问题,找到启动盘. MBR引导(master boot record):主引导记录,读取存储设备的512bytes ...
- 【Leetcode】804. Unique Morse Code Words
Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...
- Python3.6中PyInstaller不能对文件进行打包问题
上篇文章<itchat和matplotlib的结合使用爬取微信信息>是用python爬取信息得到微信朋友的信息,并且用matplotlib统计信息进行画图,所以今天想将它打包成.exe可执 ...