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
2
1000
3000
Sample Output
2.1
NO
Source
FJNU Preliminary 2005
【分析】:只要求输出一位,所以r可以从0开始一直加0.01进行枚举。根据表面积公式和体积公式可以解决本题,容积与半径的关系:v=500*r-π*i^3,在用循环测试r的一个个值。
【代码】:
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<streambuf>
#include<cmath>
#include<string>
using namespace std;
#define ll long long
#define oo 10000000
#define PI acos(-1.0)
int main()
{
int t,n,v;
double r;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
r=1e-; //1e-6就TLE了
while()
{
v=*r-PI*r*r*r;
if(v==n)
{
printf("%.1f\n",r);
break;
}
if(r>=)
{
printf("NO\n");
break;
}
r+=1e-; //枚举
}
}
}
枚举