Problem 1077 铁皮容器
Accept: 1040 Submit: 2314
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
使用白铁皮制作圆柱容器(有盖),其中每个容器耗用的铁皮量(表面积)固定为1000平方厘米。在已知容器的容积情况下,编程计算容器底半径的最小可能取值。其中容器的容积为整数,半径精确到小数点后面一位。
Input
输入的第一行含一个正整数k (1<=k<=10),表示测试例的个数。后面紧接着k行,每行对应一个测试例,含一个整数n(0<=n<=20000),代表容积。
Output
每个测试例对应一行输出,含一个实数,表示半径的值,若无解则输出“NO”。
Sample Input
210003000
Sample Output
2.1NO
Source
FJNU Preliminary 2005
列举一下圆柱的表面积公式和体积公式然后就会发现小东西了
V=PI*R*R*H
S=2*PI*R*R+2*PI*R*H
已知V和最大的S,所以表面积可以由2*V/R+2*PI*R*R
又因为题目告诉我们R取小数点后一位,那么我们从0.01往前找就是了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<sstream>
#include<cctype>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int maxn=1234;
int T;
int n,m;
int ans,flag;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int v;
scanf("%d",&v);
double r=0.01;
int flag=0;
while(1){
if(v/r+PI*r*r<=500)
break;
if(PI*r*r>500)
{
flag=1;
break;
}
r+=0.01;
}
if(!flag)
printf("%.1f\n",r);
else
printf("NO\n");
}
return 0;
}