Google中国挑战赛2005 250分题 (2)
2005-12-14 14:04
507 查看
这是9号房间的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.
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.
相关文章推荐
- Google中国挑战赛2005 250分题 (1)
- google中国编程挑战赛资格赛真题 -- BusStops(250分)
- 浅尝 Google™ Code Jam - 中国编程挑战赛
- Google CodeJam 中国编程挑战赛拉开帷幕
- Google(谷歌)全球编程挑战赛中国获奖选手(花絮)
- 参加Google™ Code Jam - 中国编程挑战赛(3)--遗憾
- [转]google编程挑战赛揭幕 中国选手有望免费赴美比赛
- google中国编程挑战赛资格赛真题 -- SkipStones
- Google™ Code Jam - 中国编程挑战赛
- Google中国编程挑战赛-题目解答
- Google中国编程挑战赛-题目解答
- Google™ Code Jam - 中国编程挑战赛模拟题二
- Google中国编程挑战赛专访李开复: 做终身程序员是一件好事情 2005.11.23
- google中国编程挑战赛题目
- google中国编程挑战赛题目FillBaskets
- google中国编程挑战赛资格赛真题 -- PlayCards
- python代码(2)---google中国编程挑战赛入围赛真题HardDuplicateRemover(1000分)
- Google™ Code Jam - 中国编程挑战赛模拟题三
- 参加Google™ Code Jam - 中国编程挑战赛(2)
- Google中国编程挑战赛第一轮