SRM 400 DIV2 [250]

#include < iostream >
#include
< vector >
#include
< cmath >
using   namespace  std;

class  GrabbingTaxi {
public:
    
int minTime(vector <int> tXs, vector <int> tYs, int gX, int gY, int walkTime, int taxiTime)
    
{
        
int ans=(abs(gX)+abs(gY))*walkTime;
        
for (int i=0;i!=tXs.size();++i)
            
if (walkTime*(abs(tXs[i])+abs(tYs[i]))+taxiTime*(abs(gX-tXs[i])+abs(gY-tYs[i]))<ans)
                ans
=walkTime*(abs(tXs[i])+abs(tYs[i]))+taxiTime*(abs(gX-tXs[i])+abs(gY-tYs[i]));
        
return ans;
    }

}
;

Problem Statement

    

You are walking in the city on a holiday. Suddenly, you are told to go to your office as soon as possible by your boss via cell phone. The city is infinite in size, with vertical streets located at every integer X value and horizontal streets located at every Y value. You are currently located at (0, 0) and your office is located at (gX, gY). There are some taxi stands in the city and their locations are (tXs[i], tYs[i]). You can either go to the office by foot or go to some taxi stand, get a taxi there and go to the office by taxi. It takes walkTime seconds to go along the street to proceed to a horizontally or vertically adjacent intersection by foot and it takes taxiTime seconds by a taxi.

Return the least amount of time that it will take you to go to your office.

Definition

    
Class: GrabbingTaxi
Method: minTime
Parameters: vector <int>, vector <int>, int, int, int, int
Returns: int
Method signature: int minTime(vector <int> tXs, vector <int> tYs, int gX, int gY, int walkTime, int taxiTime)
(be sure your method is public)
    
 

Constraints

- tXs will contain between 0 and 50 elements, inclusive.
- tXs and tYs will contain the same number of elements.
- Each element of tXs and tYs will be between -10000 and 10000, inclusive.
- gX and gY will be between -10000 and 10000, inclusive.
- walkTime and taxiTime will be between 1 and 1000, inclusive.

Examples

0)  
    
{}
{}
3
2
10
2
Returns: 50
There are no taxi stands. You have to walk to the goal.
1)  
    
{-2, -2}
{0, -2}
-4
-2
15
3
Returns: 42
First, you walk to (-2, 0) and get a taxi. Then you go to the goal by it.
2)  
    
{3}
{0}
5
0
10
20
Returns: 50
taxiTime may be larger than walkTime.
3)  
    
{34, -12, 1, 0, 21, -43, -98, 11, 86, -31}
{11, 5, -68, 69, -78, -49, -36, -2, 1, 70}
-97
-39
47
13
Returns: 2476
 
4)  
    
{82, -60, 57, 98, 30, -67, 84, -42, -100, 62}
{-7, 90, 53, -56, -15, -87, 22, -3, -61, -30}
21
15
53
2
Returns: 1908
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值