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. python基础小知识,is和==的区别,编码和解码

    1.is和==的区别 1)id() 通过id()我们可以查看到一个变量表示的值在内存中的地址 >>> s1 = "Tanxu" >>> s2 = ...

  2. Make命令完全详解教程

    Make命令完全详解教程 无论是在Linux还是在Unix环境中,make都是一个非常重要的编译命令.不管是自己进行项目开发还是安装应用软件,我们都经常要用到make或make install.利用m ...

  3. 分布式系统的CAP(Redis)

    CAP理论就是说在分布式存储系统中,最多只能实现上面的两点.而由于当前的网络硬件肯定会出现延迟丢包等问题,所以 分区容忍性是我们必须需要实现的. 所以我们只能在一致性和可用性之间进行权衡,没有NoSQ ...

  4. Java8新特性(一)——Lambda表达式与函数式接口

    一.Java8新特性概述 1.Lambda 表达式 2. 函数式接口 3. 方法引用与构造器引用 4. Stream API 5. 接口中的默认方法与静态方法 6. 新时间日期 API 7. 其他新特 ...

  5. 《UML大战需求分析》阅读笔记1

    通过阅读本书的序和第一章,让我对于UML的理解更加深刻了,并且懂了怎样把你UML学的更好. 作者先让我们明白什么是UML,大概知道了UML各个图的形态和各种用途,然后再详细的介绍各个图怎样使用. UM ...

  6. Delphi中ModalResult的使用

    Delphi中ModalResult的功能非常实用. 在自己设计的Dialog界面中,选择相应的按钮,设置按钮的 ModalResult属性为mrOK .mrCancel 等.这样的设置,当按下该按钮 ...

  7. [Hbase]hbase命令行基本操作

    -进入hbase shell hbase shell - 帮助help help - 查看hbase versionversion - 查看hbase 状态 status - 创建表create 't ...

  8. 开源版本 hadoop-2.7.5 + apache-hive-2.1.1 + spark-2.3.0-bin-hadoop2.7整合使用

    一,开源软件版本: hadoop版本 : hadoop-2.7.5 hive版本 :apache-hive-2.1.1 spark版本: spark-2.3.0-bin-hadoop2.7 各个版本到 ...

  9. 洛谷P3958 奶酪

    题目链接 这道题貌似可以用BFS来写吧qwq. 我用的是并查集,把联通的洞合并在同一个几何中,最后只需要判断是否存在上表面和下表面有相同集合的洞即可. 但是需要注意的是还有这样的一种情况:有一个大洞贯 ...

  10. (原)MongoDB在系统中的使用

    序)Nosql并不是要取代原有的数据产品,而是为不同的应用场景提供更多的选择. 一)结构类型 传统数据库的领域在于结构化文档,对于非结构化文档和半结构化文档,它能处理,但是有一定的缺陷,那么什么又是结 ...