HDOJ 1038
2013-04-12 11:14
211 查看
[align=left]Problem Description[/align]
Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attached to one of the spokes on the front wheel so that it will line up with the Hall
Effect switch once per revolution of the wheel. The speedometer monitors the sensor to count wheel revolutions. If the diameter of the wheel is known, the distance traveled can be easily be calculated if you know how many revolutions the wheel has made. In
addition, if the time it takes to complete the revolutions is known, the average speed can also be calculated.
For this problem, you will write a program to determine the total distance traveled (in miles) and the average speed (in Miles Per Hour) given the wheel diameter, the number of revolutions and the total time of the trip. You can assume that the front wheel
never leaves the ground, and there is no slipping or skidding.
[align=left]Input[/align]
Input consists of multiple datasets, one per line, of the form:
diameter revolutions time
The diameter is expressed in inches as a floating point value. The revolutions is an integer value. The time is expressed in seconds as a floating point value. Input ends when the value of revolutions is 0 (zero).
[align=left]Output[/align]
For each data set, print:
Trip #N: distance MPH
Of course N should be replaced by the data set number, distance by the total distance in miles (accurate to 2 decimal places) and MPH by the speed in miles per hour (accurate to 2 decimal places). Your program should not generate any output for the ending case
when revolutions is 0.
Constants
For p use the value: 3.1415927.
There are 5280 feet in a mile.
There are 12 inches in a foot.
There are 60 minutes in an hour.
There are 60 seconds in a minute.
There are 201.168 meters in a furlong.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
[/code]
Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attached to one of the spokes on the front wheel so that it will line up with the Hall
Effect switch once per revolution of the wheel. The speedometer monitors the sensor to count wheel revolutions. If the diameter of the wheel is known, the distance traveled can be easily be calculated if you know how many revolutions the wheel has made. In
addition, if the time it takes to complete the revolutions is known, the average speed can also be calculated.
For this problem, you will write a program to determine the total distance traveled (in miles) and the average speed (in Miles Per Hour) given the wheel diameter, the number of revolutions and the total time of the trip. You can assume that the front wheel
never leaves the ground, and there is no slipping or skidding.
[align=left]Input[/align]
Input consists of multiple datasets, one per line, of the form:
diameter revolutions time
The diameter is expressed in inches as a floating point value. The revolutions is an integer value. The time is expressed in seconds as a floating point value. Input ends when the value of revolutions is 0 (zero).
[align=left]Output[/align]
For each data set, print:
Trip #N: distance MPH
Of course N should be replaced by the data set number, distance by the total distance in miles (accurate to 2 decimal places) and MPH by the speed in miles per hour (accurate to 2 decimal places). Your program should not generate any output for the ending case
when revolutions is 0.
Constants
For p use the value: 3.1415927.
There are 5280 feet in a mile.
There are 12 inches in a foot.
There are 60 minutes in an hour.
There are 60 seconds in a minute.
There are 201.168 meters in a furlong.
[align=left]Sample Input[/align]
26 1000 5 27.25 873234 3000 26 0 1000
[align=left]Sample Output[/align]
Trip #1: 1.29 928.20 Trip #2: 1179.86 1415.84 我的代码如下:[code]#include <iostream> using namespace std; #define PI 3.1415927 int main() { float diameter,time; int revolutions; int count=0; float distance,MPH; while(scanf("%f%d%f",&diameter,&revolutions,&time)&&revolutions!=0) { distance=PI*diameter*revolutions/(5280*12); MPH=distance*3600/time; count++; printf("Trip #%d: %.2f %.2f\n",count,distance,MPH); } return 0; }
[/code]
相关文章推荐
- ACM水题系列 HDOJ1038
- hdoj1038简单题
- HDOJ1038 Biker's Trip Odometer
- { double }hdoj1038
- HDOJ1038 Biker's Trip Odometer
- hdoj1038 Biker's Trip Odometer(zz)
- hdoj-1038 数学题
- HDOJ 2048 神、上帝以及老天爷(组合数学,全错位排列)
- HDOJ 采矿(java)
- hdoj 2277 Change the ball 【找规律】
- HDOJ 1863 畅通工程 (最小生成树)
- hdoj 1517 A Multiplication Game(博弈)
- hdoj 2476 String painter(dp)
- 计算几何-hdoj-1147-Pick-up sticks
- hdoj 2277 Change the ball 【找规律】
- 【HDOJ】2242 考研路茫茫——空调教室
- hdoj-【3501 Calculation 2】
- hdoj 2147(博弈论)
- HDOJ 1176 免费馅饼 dp变形
- 【HDOJ 1086】 模板水过