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 ...
随机推荐
- ECSHOP和SHOPEX快递单号查询德邦插件V8.6专版
发布ECSHOP说明: ECSHOP快递物流单号查询插件特色 本ECSHOP快递物流单号跟踪插件提供国内外近2000家快递物流订单单号查询服务例如申通快递.顺丰快递.圆通快递.EMS快递.汇通快递.宅 ...
- scala成长之路(3)隐式转换
不废话,先上例子:定义一个参数类型为String的函数: scala> def sayHello(name:String) = println("hello " + name ...
- python循环,函数
平常的网页会转换成ascll码,在转编译成十六进制a='http://www.mywebsit.com/?query=python&count=20'print(a)b=a.replace(' ...
- 05 redis(进阶)
redis 阶段一.认识redis 1.什么是redis Redis是由意大利人Salvatore Sanfilippo(网名:antirez)开发的一款内存高速缓存数据库.Redis全称为:Remo ...
- [Cracking the Coding Interview] 4.4 Check Balanced
Implement a function to check if a binary tree is balanced. For the purpose of this question, a bala ...
- Spring事务:一种编程式事务,三种声明式事务
事务隔离级别 隔离级别是指若干个并发的事务之间的隔离程度.TransactionDefinition 接口中定义了五个表示隔离级别的常量: TransactionDefinition.ISOLATIO ...
- mysql用命令创建用户创建数据库设置权限
1.create database bbs; //创建数据库 2.create user bbs IDENTIFIED by 'bbs'; //创建用户bbs和登录密码bbs 3.grant AL ...
- WPF 构建无外观(Lookless)控件
原文:WPF 构建无外观(Lookless)控件 构建一个用户可以使用Template属性设置外观的WPF控件需要以下几步 1.继承自System.Windows.Controls.Control 2 ...
- qt 编译unresolved external symbol的错误解决
题外问题:.rc文件报错,里面引用的.h文件打不开. 方法:rc文件移除,然后重新添加就可以: unresolved external symbol的原因: 1.没有添加编译生成的moc文件,添加对应 ...
- java网络编程框架
虽然写过一些网络编程方面的东西,但还没有深入研究过这方面的内容,直接摘录一些文章,后续整理 原文地址:http://blog.csdn.net/lwuit/article/details/730613 ...