题目链接:点击打开链接
题意:跑道,直跑道和弧形跑道的全长400米,两个弧在同一个圆上,直跑道和弧形跑道对应的宽的比为a:b,求出长、宽的具体值?
思路:简单的数学公式即可,由图:
角r = atan(a / b),r为弧度制
又2 * R * (PI - 2 * r) + 4 * R * cos(PI / 2 - r)= 400,即R * (PI - 2 * r)+ 2 * R *sin(r) = 200
得:
R = 200 / (PI - 2 * r + 2 * sin(r))
从而求出长宽:
length = 2 * R * sin(r),width = 2 * R * cos(r)
// LightOJ 1056 Olympics.cpp 4ms/500ms
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define PI acos(-1)
int main(){
int t, cases = 0;
int a, b;
scanf("%d", &t);
while (t--) {
scanf("%d : %d", &a, &b);
double r = atan((double)a / b);//角(弧度)
double R = 200.0 / (PI - 2 * r + 2 * sin(r));//半径
double length = 2 * R * sin(r);//长
double width = 2 * R * cos(r);//宽
printf("Case %d: %f %f\n", ++cases,length, width);
}
return 0;
}