[LightOJ] [1137] Expanding Rods

Problem Description

Loading...

Problem Analysis

We can derive the equations relating the arc radius r and h

$\sqrt{r^2-(\dfrac{l}{2})^2}+h=r$ ①
$2*arsin(\dfrac{l}{2r})*r=l’$②

Equation ① can be simplified to
$r=\dfrac{h^2+\dfrac{l^2}{4}}{2h}$
Substituting it into equation ② gives l'

Compare it with the l’ obtained from the problem data
this yields the comparison relation between mid and res
so Binary Search can be performed

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<stdio.h>
#include<math.h>
double L,n,c;
bool judge(double m) {
	double t=(m*m+L*L/4.0)/m/2.0;
	if(2*asin(L/2.0/t)*t>=(1+n*c)*L)
		return true;
	else
		return false;
}
int main() {
	int T,kase=0;
	scanf("%d",&T);
	while(T--) {
		scanf("%lf %lf %lf",&L,&n,&c);
		double l=0,r=L;
		while(r-l>1e-8) {
			double mid=(l+r)/2;
			if(judge(mid))
				r=mid;
			else
				l=mid;
		}
		printf("Case %d: %.8lf\n",++kase,r);
	}
	return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...