#T789. 骑车与走路
骑车与走路
Description
In the Tsinghua campus, life would be very inconvenient without a bicycle when attending classes or handling errands. However, in reality, biking isn't always faster for every task because it involves finding a bike, unlocking it, parking, and locking it again, which takes some time.
Assume the following:
- The time to find a bike, unlock it, and mount it is 27 seconds.
- The time to park and lock the bike is 23 seconds.
- Walking speed is 1.2 meters per second.
- Biking speed is 3.0 meters per second.
Given these parameters, determine whether biking or walking is faster for different distances.
- If biking is faster, output
"Bike". - If walking is faster, output
"Walk". - If both take the same time, output
"All".
Input Format
The input consists of a single line containing an integer representing the distance (in meters) to travel for the errand.
Output Format
Output a single line:
"Bike"if biking is faster,"Walk"if walking is faster,"All"if both take the same time.
Example Calculation
For a given distance ( d ):
- Total biking time = Time to mount + Time to ride + Time to park
[ T_{\text{bike}} = 27 + \frac{d}{3.0} + 23 ] - Total walking time = Time to walk
[ T_{\text{walk}} = \frac{d}{1.2} ]
Compare ( T_{\text{bike}} ) and ( T_{\text{walk}} ) to determine the faster method.
Constraints
- The input distance ( d ) is a positive integer.
Solution Code
d = int(input())
bike_time = 27 + 23 + d / 3.0
walk_time = d / 1.2
if bike_time < walk_time:
print("Bike")
elif walk_time < bike_time:
print("Walk")
else:
print("All")
This code reads the input distance, computes the total time for biking and walking, compares them, and prints the appropriate result.
120
Bike
译文
CodesOnline