Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <math.h>
- using namespace std;
- const double eps=1e-12;
- double pi;
- int n,f,_42;
- double r[10010];
- inline int cmp(double a, double b) {
- return (a-b>eps? 1 : (b-a>eps? -1 : 0));
- }
- inline double area(double rad) {
- return rad*rad*pi;
- }
- bool can(double sz) {
- double rem=area(r[0]);
- int fr=0;
- for (int i=0; i<n; )
- if (cmp(rem,sz)>=0)
- rem-=sz, fr++;
- else
- rem=area(r[++i]);
- return fr>=f+1;
- }
- int main() {
- pi = acos(-1.0);
- scanf("%d", &_42);
- while (_42--) {
- scanf("%d %d", &n,&f);
- for (int i=0; i<n; i++)
- scanf("%lf" ,&r[i]);
- double beg=0, end=area(*max_element(r,r+n));
- for (int i=0; i<50; i++) {
- double mid=(beg+end)/2.0;
- if (can(mid)) beg=mid;
- else end=mid;
- }
- printf("%.4lf\n", beg);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement