The dog task
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 2559   Accepted: 1038   Special Judge

Description

Hunter Bob often walks with his dog Ralph. Bob walks with a constant speed and his route is a polygonal line (possibly self-intersecting) whose vertices are specified by N pairs of integers (Xi, Yi) ? their Cartesian coordinates. 
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

The first line of the input contains two integers N and M, separated by a space ( 2 <= N <= 100 ,0 <= M <=100 ). The second line contains N pairs of integers X1, Y1, ..., XN, YN, separated by spaces, that represent Bob's route. The third line contains M pairs of integers X1',Y1',...,XM',YM', separated by spaces, that represent interesting places. 
All points in the input file are different and their coordinates are integers not greater than 1000 by the absolute value. 

Output

The first line of the output should contain the single integer K ? the number of vertices of the best dog's route. The second line should contain K pairs of coordinates X1'',Y1'' , ...,Xk'',Yk'', separated by spaces, that represent this route. If there are several such routes, then you may write any of them.

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 (二分匹配)的更多相关文章

  1. POJ 1034 The dog task(二分图匹配)

    http://poj.org/problem?id=1034 题意: 猎人和狗一起出去,狗的速度是猎人的两倍,给出猎人的路径坐标,除了这些坐标外,地图上还有一些有趣的点,而我们的狗,就是要尽量去多的有 ...

  2. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  3. TTTTTTTTTTTTTTTTT POJ 2226 草地覆木板 二分匹配 建图

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9754   Accepted: 3618 Desc ...

  4. TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5004   Accepted: 1444 ...

  5. POJ 1466 大学谈恋爱 二分匹配变形 最大独立集

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 11694   Accepted: 5230 D ...

  6. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  7. HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)

    题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...

  8. poj 1274 The Prefect Stall - 二分匹配

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22736   Accepted: 10144 Description Far ...

  9. poj 1274 The Perfect Stall (二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17768   Accepted: 810 ...

随机推荐

  1. Vue使用json-server来进行后端数据模拟

    正开发过程中 前后端分离或者不分离 ,接口多半是之后与页面的开发 ,所以建立rest的APL的接口 给前端提供虚拟的数据是非常必要的 所以这里我使用了json-server作为工具,支持CORS和JS ...

  2. linux上面安装LAMP环境

    一.安装php 1.1.yum安装php yum -y install php 1.2..安装PHP扩展 yum -y install php-mysql php-gd php-imap php-ld ...

  3. PHP (Yii2) 自定义业务异常类(可支持返回任意自己想要的类型数据)

    public function beforeAction($action) { return parent::beforeAction($action); } public function runA ...

  4. 初识python 面向对象

    what the f**k!!这个知识点学不好的最大元凶就是,我还单身??? python基础(四): 面向对象的三个特点: 封装,继承,多态 类: 对象是面向对象编程的核心,在使用对象的过程中,为了 ...

  5. Table被web编程弃用的原因

    Table要比其它html标记占更多的字节. (延迟下载时间,占用服务器更多的流量资源.)Tablle会阻挡浏览器渲染引擎的渲染顺序. (会延迟页面的生成速度,让用户等待更久的时间.)Table里显示 ...

  6. mysql5.7.19安装报错 无法定位程序输入点

    https://blog.csdn.net/t876587201/article/details/79503688

  7. 深入了解jQuery Mobile-1

    介绍 jQuery Mobile是一种触控优化的HTML5 UI框架,旨在制作可在所有智能手机,平板电脑和台式机设备上访问的响应式网站和应用程序 移动页面结构 jQuery Mobile站点必须以HT ...

  8. (数据科学学习手札20)主成分分析原理推导&Python自编函数实现

    主成分分析(principal component analysis,简称PCA)是一种经典且简单的机器学习算法,其主要目的是用较少的变量去解释原来资料中的大部分变异,期望能将现有的众多相关性很高的变 ...

  9. ABAP CDS ON HANA-(8)算術式

    Arithmetic expression in CDS View Allowed Arithmetic operators in CDS view. CDS View- @AbapCatalog.s ...

  10. java 解析xml 多命名空间问题

    先贴段有命名空间的xml吧.. <feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3. ...