PKU 3365 Cylinder 題解
計算幾何問題公式也很容易推出來
也是敏哥做的
比賽時候我們第一個完成的
1
#include<stdio.h>
2
#include<math.h>
3
4
#define PI acos(-1)
5
6
int main()
7

{
8
double x,y,s,r,V,tmp;
9
while(scanf("%lf%lf",&x,&y),x || y)
10
{
11
if(x < y)
12
{
13
tmp = x;
14
x = y;
15
y = tmp;
16
}
17
s = x/(PI+1);
18
r = s/2;
19
if(s > y)
20
{
21
r = y/2;
22
}
23
V = PI*r*r*y;
24
r = y/(2*PI);
25
if(V < (x-2*r)*PI*r*r)
26
{
27
V = (x-2*r)*PI*r*r;
28
}
29
printf("%.3lf\n",V);
30
}
31
return 0;
32
}
33
34
35
#include<stdio.h>2
#include<math.h>3
4
#define PI acos(-1)5

6
int main()7


{8
double x,y,s,r,V,tmp;9
while(scanf("%lf%lf",&x,&y),x || y)10

{11
if(x < y)12

{13
tmp = x;14
x = y; 15
y = tmp;16
}17
s = x/(PI+1);18
r = s/2;19
if(s > y)20

{21
r = y/2;22
}23
V = PI*r*r*y;24
r = y/(2*PI);25
if(V < (x-2*r)*PI*r*r)26

{27
V = (x-2*r)*PI*r*r;28
}29
printf("%.3lf\n",V);30
}31
return 0;32
}33

34

35


