北大poj- 1034
The dog task
Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 3272 | Accepted: 1313 | 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
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
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
Source Code
Problem:
Memory: 416K Time: 16MS
Language: GCC Result: Accepted #include <stdio.h>
#include <math.h>
#include <string.h> #define DOG_SPEED 2 #define MAX_POINT_NUM 101 #define TRUE (int)1
#define FALSE (int)0 typedef int BOOL; typedef struct
{
int x;
int y;
}Point; typedef struct
{
int num;
Point pos[MAX_POINT_NUM];
}Points; Points g_Bob;
Points g_interests;
BOOL g_isOccupied[MAX_POINT_NUM];
int g_len[MAX_POINT_NUM][MAX_POINT_NUM];
int g_selectNum;
int g_selectIdx[MAX_POINT_NUM];
int g_BobToInterest[MAX_POINT_NUM]; void Input()
{
int i; scanf("%d %d", &g_Bob.num, &g_interests.num); for(i = ; i < g_Bob.num; i++)
{
scanf("%d %d", &g_Bob.pos[i].x, &g_Bob.pos[i].y);
} for(i = ; i < g_interests.num; i++)
{
scanf("%d %d", &g_interests.pos[i].x, &g_interests.pos[i].y);
} g_selectNum = ;
memset(g_len, -, sizeof(g_len));
memset(g_selectIdx, -, sizeof(g_selectIdx));
memset(g_BobToInterest, -, sizeof(g_BobToInterest));
} void Output()
{
int bobIdx, interestIdx; printf("%d\n", g_Bob.num+g_selectNum); for(bobIdx = ; bobIdx < g_Bob.num; bobIdx++)
{
printf("%d %d ", g_Bob.pos[bobIdx].x, g_Bob.pos[bobIdx].y);
interestIdx = g_BobToInterest[bobIdx];
if(interestIdx != -) printf("%d %d ", g_interests.pos[interestIdx].x, g_interests.pos[interestIdx].y);
}
} static double CalcLen(Point* m, Point* n)
{
double x = m->x - n->x;
double y = m->y - n->y; return sqrt(x*x+y*y);
} int IsLenSatisfied(int bobIdx, int interestIdx)
{
double bobLen, dogLen1, dogLen2; if(g_len[bobIdx][interestIdx] == -)
{
bobLen = CalcLen(&g_Bob.pos[bobIdx], &g_Bob.pos[bobIdx+]);
dogLen1 = CalcLen(&g_Bob.pos[bobIdx], &g_interests.pos[interestIdx]);
dogLen2 = CalcLen(&g_Bob.pos[bobIdx+], &g_interests.pos[interestIdx]);
g_len[bobIdx][interestIdx] = ((bobLen*DOG_SPEED) >= (dogLen1+dogLen2)) ? : ;
}
return g_len[bobIdx][interestIdx];
} BOOL DogFinding(int bobIdx)
{
int interestIdx; for(interestIdx = ; interestIdx < g_interests.num; interestIdx++)
{
if(!g_isOccupied[interestIdx] && IsLenSatisfied(bobIdx, interestIdx))
{
g_isOccupied[interestIdx] = TRUE;
if(g_selectIdx[interestIdx] == - || DogFinding(g_selectIdx[interestIdx]))
{
g_selectIdx[interestIdx] = bobIdx;
g_BobToInterest[bobIdx] = interestIdx;
return TRUE;
}
}
} return FALSE;
} void Proc()
{
int bobIdx;
for(bobIdx = ; bobIdx < g_Bob.num-; bobIdx++)
{
memset(g_isOccupied, , sizeof(g_isOccupied));
if(DogFinding(bobIdx)) g_selectNum++;
}
} int main()
{
Input();
Proc();
Output();
return ;
}
北大poj- 1034的更多相关文章
- 北大POJ题库使用指南
原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列 ...
- POJ 1034 The dog task(二分图匹配)
http://poj.org/problem?id=1034 题意: 猎人和狗一起出去,狗的速度是猎人的两倍,给出猎人的路径坐标,除了这些坐标外,地图上还有一些有趣的点,而我们的狗,就是要尽量去多的有 ...
- poj 1034 The dog task (二分匹配)
The dog task Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2559 Accepted: 1038 Sp ...
- 【Java】深深跪了,OJ题目Java与C运行效率对比(附带清华北大OJ内存计算的对比)
看了园友的评论之后,我也好奇清橙OJ是怎么计算内存占用的.重新测试的情况附在原文后边. -------------------------------------- 这是切割线 ----------- ...
- POJ 1861 Network (Kruskal算法+输出的最小生成树里最长的边==最后加入生成树的边权 *【模板】)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14021 Accepted: 5484 Specia ...
- 各大OJ
北大POJ 杭电HDU 浙大ZOj 蓝桥杯 PAT
- leetcode学习笔记--开篇
1 LeetCode是什么? LeetCode是一个在线的编程测试平台,国内也有类似的Online Judge平台.程序开发人员可以通过在线刷题,提高对于算法和数据结构的理解能力,夯实自己的编程基础. ...
- OJ题目JAVA与C运行效率对比
[JAVA]深深跪了,OJ题目JAVA与C运行效率对比(附带清华北大OJ内存计算的对比) 看了园友的评论之后,我也好奇清橙OJ是怎么计算内存占用的.重新测试的情况附在原文后边. ----------- ...
- C++ 指针常见用法小结
1. 概论 2.指针基础 3. 指针进阶 4. 一维数组的定义与初始化 5. 指针和数组 6. 指针运算 7. 多维数组和指针 8. 指针形参 9. 数组形参 10. 返回指针和数组 11. 结语 ...
- 几个比較好的IT站和开发库官网
几个比較好的IT站和开发库官网 1.IT技术.项目类站点 (1)首推CodeProject,一个国外的IT站点,官网地址为:http://www.codeproject.com,这个站点为程序开发人员 ...
随机推荐
- 2018-2019-2 20175317 实验二《Java面向对象程序设计》实验报告
2018-2019-2 20175317 实验二<Java面向对象程序设计>实验报告 一.实验步骤及内容 面向对象程序设计-1 参考 http://www.cnblogs.com/roce ...
- LeetCode--036--有效的数独(java)
判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗实线分隔的 ...
- DPDK kni创建要先于port开启
DPDK kni创建要先于port开启 1. DPDK kni创建使用API:- rte_kni_init- rte_kni_alloc 2. DPDK port开启使用API:- rte_eth_d ...
- Python实现:汉诺塔问题
汉诺塔问题不管在任何编程语言里都是经典问题,是采用递归算法的经典案例,该问题可以抽象如下: 一 .3根圆柱A,B,C,其中A上面串了n个圆盘 二 .这些圆盘从上到下是按从小到大顺序排列的,大的圆盘任何 ...
- 自动化定位——通过XPath定位元素
XPath是一种XML文档中定位元素的语言.该定位方式也是比较常用的定位方式 1通过属性定位元素 find_element_by_xpath("//标签名[@属性='属性值']") ...
- 使用shiro的密码服务模块
http://jinnianshilongnian.iteye.com/blog/2021439 http://www.cnblogs.com/snidget/p/3817763.html
- vue-lazyload懒加载插件的使用
vue-lazyload懒加载插件的使用其实很简单,不想vue-loader官网用法写的那么简单.下面代码演示: 1.安装插件 npm install vue-lazyload --save 2. ...
- react-redux中的数据传递
1.connect connect用于连接React组件与 Redux store,其使用方法如下 connect([mapStateToProps], [mapDispatchToProps], [ ...
- 什么是ORM?
什么是ORM? MVC框架中重要的一部分就是ORM,实现了数据模型与数据库的解耦,即数据模型不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库. ORM是对象关系映射的简称,主要任务是: 根 ...
- 关于:无法创建链接服务器 "ORCL" 的 OLE DB 访问接口 "OraOLEDB.Oracle" 的实例 (错误:7302)
本人接触和使用Oracle数据库才有一个季度的时间,问题比较白,大神请无视本文. 环境: 1.数据服务器,windows2008R2,Oracle11g 2.报表服务器,windows2008R2,S ...