UVa 12853 - The Pony Cart Problem

contents

  1. 1. Problem
  2. 2. Sample Input
  3. 3. Sample Output
  4. 4. Solution

Problem

現在有一台馬車繞行一個圓,馬車內側輪胎畫出小圓、外側畫出大圓,現在知道馬車內側與外側輪胎之間的距離 D,同時知道內側輪胎每滾一圈,外側輪胎會滾 N 圈,請問外側輪胎畫出來的圓周長為何?

Sample Input

1
2
3
4
3
5.00 2.00
4.20 1.44
8.03 2.01

Sample Output

1
2
3
Case 1: 62.832
Case 2: 86.365
Case 3: 100.40

Solution

感謝峻維兄熱心翻譯

假設內側輪胎畫出小圓半徑為 A,兩個輪胎的半徑 B

$$\frac{ \frac{ 2 \pi A}{2 \pi B} }{ \frac{2 \pi (A + D)}{2 \pi A} } = N \\ \Rightarrow A = \frac{D}{N-1}$$

所求為$2 \pi (A+D)$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <math.h>
int main() {
int testcase, cases = 0;
const double pi = acos(-1);
double D, N, A;
scanf("%d", &testcase);
while (testcase--) {
scanf("%lf %lf", &D, &N);
A = D / (N - 1);
double ret = 2 * pi * (A + D);
printf("Case %d: %.3lf\n", ++cases, ret);
}
return 0;
}