有 f + 1 个人来分 n 个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,并且面积要相同。求每个人最多能得到多大面积的派(不必是圆形)。

这题很好做,使用二分法就OK。

首先在读取所有派的半径后处理出所有派的面积,并且记录最大的那个派的面积。然后从 0 ~ maxsize 二分枚举一下,就能得到答案。

此外,这道题最后输出保留小数位数可以是 3, 4, 5,都可以。

附AC代码:

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <cstdarg>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <list>
#include <vector>
#include <map>
long
sizeof(a))
namespace std;
int count, ...)
  16: {
  17:     va_list arg_ptr;
  18:     va_start (arg_ptr, count);
int i = 0; i < count; i++)
int*));
  21:     va_end(arg_ptr);
  22: }
  23:  
double PI = acos(-1.0);
double buf[10009];
int n, f;
  27:  
double size)
  29: {
int res = 0;
int i = 1; i <= n; i++)
  32:         res += floor(buf[i] / size);
return (res >= (f + 1));
  34: }
  35:  
int main()
  37: {
int T;
, &T);
while (T--)
  41:     {
double m = -1;
, &n, &f);
int i = 1; i <= n; i++)
  45:         {
int r;
, &r);
  48:             buf[i] = PI * r * r;
  49:             m = max(m, buf[i]);
  50:         }
double tmp = 0.0;
while (m - tmp > 1e-5)
  53:         {
double p = (m + tmp) / 2.0;
if (Deal(p)) tmp = p;
else m = p;
  57:         }
, tmp);
  59:     }
return 0;
  61: }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-08-04
  • 2022-12-23
  • 2021-08-03
  • 2021-07-04
猜你喜欢
  • 2022-01-15
  • 2021-12-03
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-12-24
  • 2021-09-13
相关资源
相似解决方案