Problem Link
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int n, f;
double radius[10001];
bool isVolumePossible(double p)
{
int total = 0;
for(int i = 0; i < n; i++)
{
total += (int)floor((M_PI * radius[i]) / p);
}
if(total >= f + 1)
return true;
return false;
}
void solve(double s, double e)
{
double result = 0.0;
for(int i = 0; i < 60; i++)
{
double mid = (e + s) / 2.0;
if(isVolumePossible(mid))
{
s = mid;
result = mid;
}
else
{
e = mid;
}
}
printf("%.4lf\n", result);
}
int main()
{
double maxVolume = 0;
int t;
cin >> t;
while(t--)
{
cin >> n >> f;
memset(radius, 0, sizeof radius);
for(int i = 0; i < n; i++)
{
cin >> radius[i];
radius[i] *= radius[i];
}
maxVolume = 4e8;
solve(0.0, maxVolume);
}
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int n, f;
double radius[10001];
bool isVolumePossible(double p)
{
int total = 0;
for(int i = 0; i < n; i++)
{
total += (int)floor((M_PI * radius[i]) / p);
}
if(total >= f + 1)
return true;
return false;
}
void solve(double s, double e)
{
double result = 0.0;
for(int i = 0; i < 60; i++)
{
double mid = (e + s) / 2.0;
if(isVolumePossible(mid))
{
s = mid;
result = mid;
}
else
{
e = mid;
}
}
printf("%.4lf\n", result);
}
int main()
{
double maxVolume = 0;
int t;
cin >> t;
while(t--)
{
cin >> n >> f;
memset(radius, 0, sizeof radius);
for(int i = 0; i < n; i++)
{
cin >> radius[i];
radius[i] *= radius[i];
}
maxVolume = 4e8;
solve(0.0, maxVolume);
}
return 0;
}
Comments
Post a Comment