Moving By Points (topcoder SRM 738 DIV 2)

本文探讨了在一个二维坐标系中,如何通过增加最少数量的障碍物移除,实现从起点到终点的可达性。文章详细阐述了问题背景,即在N个整数点构成的网格上,如何在限制条件下,找到从点0到点N-1的最短路径,同时确保路径上的每一步都在已知点或新增点上。

Problem Statement

You are given N points. The points are numbered from 0 to N-1. Point i has coordinates (X[i], Y[i]). Note that the given points are not necessarily distinct.

You have to move from point 0 to point N-1. You have to move in steps. In each step you can move by 1 unit of distance in one of the four cardinal directions. That is, if you are at coordinates (x,y), you can move to (x-1,y), (x+1,y), (x,y+1), or (x,y-1). Additionally, you can only step on points, you cannot enter coordinates that don’t contain a point.

For the given N points it may be impossible to get from point 0 to point N-1 according to the above rules. Compute and return the smallest number of additional points that have to be added to the collection in order to be able to do that.

Definition

Class: MovingByPoints
Method: countMinimumPoints
Parameters: int, vector <int>, vector <int>
Returns: int
Method signature: int countMinimumPoints(int N, vector <int> X, vector <int> Y)
(be sure your method is public)
Limits

Time limit (s): 2.000
Memory limit (MB): 256
Constraints

  • N will be between 1 and 500, inclusive.
  • X and Y will each have exactly N elements.
  • Each element of X and Y will be between 1 and 10^6, inclusive.

Examples

(0)

3
{0,1,2}
{0,1,2}
Returns: 2

You want to be able to walk from (0,0) to (2,2). In order to be able to do that, you need to add two more points. One of multiple optimal solutions is to add the points (1,0) and (1,2).
(1)

4
{1,1,1,3}
{1,2,3,3}
Returns: 1

(2)

10
{1,1,1,2,3,3,4,5,5,5}
{1,2,3,3,3,2,2,2,3,4}
Returns: 0

(3)

7
{2,3,4,5,6,6,5}
{2,1,1,1,2,3,4}
Returns: 3

(4)

2
{2,2}
{2,2}
Returns: 0

Here you want to travel from (2,2) to (2,2). That is trivially possible, without having to add more points.

Note that the point (2,2) is given twice. This has exactly the same effect as if it were given only once.

(5)

20
{260522,436426,648772,933447,703497,407775,963982,968417,631932,895728,723857,286918,539679,63340,361868,287940,224593,836991,823355,11431}
{914575,979445,690081,190629,47202,894325,804784,302156,735902,78537,330739,329211,238506,686568,660016,296263,601449,890310,177068,8580}
Returns: 1155084

题目大意

在一个二维坐标系中,有N个整数点,编号是0…N-1,坐标是(X[i],Y[i])。在初始状态下,只有这n个点可以走,其他点均有障碍物不能走。每次走可以选择往择上下左右相邻的任何一个没有障碍物的点走。问,最少去除多少个障碍物,使得可以从0号点走到N-1号点。
1<=N<=500, 1<=X[i],Y[i]<=10^6

解答

解答和AC代码将在一周后给出。

AC代码

class MovingByPoints
{
public:
    int countMinimumPoints(int N, vector<int> X, vector<int> Y)
    {

    }
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值