Description
使用白铁皮制作圆柱容器(有盖),其中每个容器耗用的铁皮量(表面积)固定为1000平方厘米。在已知容器的容积情况下,编程计算容器底半径的最小可能取值。其中容器的容积为整数,半径精确到小数点后面一位。
Input
输入的第一行含一个正整数k (1<=k<=10),表示测试例的个数。后面紧接着k行,每行对应一个测试例,含一个整数n(0<=n<=20000),代表容积。
Output
每个测试例对应一行输出,含一个实数,表示半径的值,若无解则输出“NO”。
Sample Input
2
1000
3000
1000
3000
Sample Output
2.1
NO
NO
AC代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
const double pi=3.141592565;
int main()
{
int i, N;
double r,v;
cin>>N;
while(N--)
{
scanf("%lf",&v);
int flag=1;
double minx=10000.0;
for(r=0.01; ; r=r+0.01)
{
if(pi*r*r>500)
break;
if(v/r+pi*r*r<=500)
{
if(r<minx)
{
minx=r;
}
flag=0;
}
}
if(flag)
printf("NO\n");
else
printf("%.1lf\n",minx);
}
return 0;
}