Blue Bridge Cup Topic 1111: Cylinder (C language)

Question 1111: Cylinder

Time limit: 1Sec Memory limit: 128MB Submit: 1567 Resolution: 607

Title description

Using a piece of paper and scissors, you can cut two surfaces form a cylinder in the following manner:


the horizontal cutting paper (parallel to the shorter side), to obtain two rectangular portions.
The first portion starts from the maximum radius of the circle was cut out
circle. The circle will form the bottom of the cylinder.
Rolling up the second part, to be equal to the circumferential perimeter, and the volume is connected to one end of the circle
on. Please note that the volume may have some overlapping parts to obtain the desired perimeter. Given the
size of the paper, you can calculate the maximum body can be constructed using the above procedure of the cylinder
product?

enter

‎The input consists of several test cases. Each test case consists of two w and h (1≤w ≤h≤100), which represent the width and height of the paper. The last
test case containing two zeros behind
the line.

Output

‎For each test case, print a line, where the maximum volume possible is the cylinder. Cycle this number to 3 digits after the decimal point.

Sample input
<span style="color:#333333"><span style="color:#333333">10 10
10 50
10 30
0 0

</span></span>
Sample output
<span style="color:#333333"><span style="color:#333333">54.247
785.398
412.095</span></span>

 Ideas:

There is no idea (straightforward), it's just a math problem. Let's draw a picture and discuss the situation.

You can refer to the explanation of this big guy: https://blog.dotcpp.com/a/2608

 Implementation code:

#include <stdio.h>
#define PI 3.1415926535897932
int main()
{
	double w,h,r,r1,r2;/*r1:结果1,r2:结果2*/
	while(scanf("%lf%lf",&w,&h))
	{
		if(w==0&&h==0)
		break;
		r=h/(2*PI+2);/*以h-2r为周长时,w为圆柱的高*/
		if(r*2>w)
		{
			r=w/2;
		}
		r1=PI*r*r*w;
		r=w/(2*PI);/*以w为圆柱的周长*/
		r2=PI*r*r*(h-2*r); 
		/*输出结果*/
		printf("%.3lf\n",(r1>r2)?r1:r2);
	}
	return 0;
 } 

 

Guess you like

Origin blog.csdn.net/with_wine/article/details/114214697