Google编程大赛入围赛250分真题

Google编程大赛入围赛250分真题


  Problem Statement
  
????
  
You are given a String[] cityMap representing the layout of a city. The city
  
consists of blocks. The first element of cityMap represents the first row of
  
blocks, etc. A 'B' character indicates a location where there is a bus stop.
  
There will be exactly one 'X' character, indicating your location. All other
  
characters will be '.'. You are also given an int walkingDistance, which is the
  
maximum distance you are willing to walk to a bus stop. The distance should be
  
calculated as the number of blocks vertically plus the number of blocks
  
horizontally. Return the number of bus stops that are within walking distance of
  
your current location. Definition
  
????
  
Class:
  
BusStops
  
Method:
  
countStops
  
Parameters:
  
String[], int
  
Returns:
  
int
  
Method signature:
  
int countStops(String[] cityMap, int walkingDistance)
  
(be sure your method is public)
  
????

  
Constraints
  
-
  
cityMap will contain between 1 and 50 elements, inclusive.
  
-
  
Each element of cityMap will contain between 1 and 50 characters, inclusive.
  
-
  
Each element of cityMap will contain the same number of characters.
  
-
  
Each character of each element of cityMap will be 'B', 'X', or '.'.
  
-
  
There will be exactly one 'X' character in cityMap.
  
-
  
walkingDistance will be between 1 and 100, inclusive.
  
Examples
  
0)

  
????
  
{"...B.",
  
".....",
  
"..X.B",
  
".....",
  
"B...."}
  
3
  
Returns: 2
  
You can reach the bus stop at the top (3 units away), or on the right (2 units
  
away). The one in the lower left is 4 units away, which is too far. 1)

  
????
  
{"B.B..",
  
".....",
  
"B....",
  
".....",
  
"....X"}
  
8
  
Returns: 3
  A distance of 8 can get us anywhere on the map, so we can reach all 3 bus stops.
  
2)

  
????
  
{"BBBBB",
  
"BB.BB",
  
"B.X.B",
  
"BB.BB",
  
"BBBBB"}
  
1
  
Returns: 0
  
Plenty of bus stops, but unfortunately we cannot reach any of them.
  
3)

  
????
  
{"B..B..",
  
".B...B",
  
"..B...",
  
"..B.X.",
  
"B.B.B.",
  
".B.B.B"}
  
3
  
Returns: 7

  
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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值