Pie 二分

Pie 二分

Time limit:1000 ms Memory limit:65536 kB Source: Northwestern Europe 2006 Special judge: Yes

描述

My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.

My friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size.

What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.

输入

One line with a positive integer: the number of test cases. Then for each test case:
One line with two integers N and F with 1 ≤ N, F ≤ 10 000: the number of pies and the number of friends.
One line with N integers ri with 1 ≤ ri ≤ 10 000: the radii of the pies.

输出

For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10 −3.

Input

3
3 3
4 3 3
1 24
5
10 5
1 4 2 3 4 5 6 5 4 2

Output

25.1327
3.1416
50.2655

代码

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctype.h>
#include <stdio.h>
#include <string.h>


#define PI 3.14159265358979383246
#define LL long long
#define INF 0x3f3f3f3f  

#define _for(i, a) for(int i = 0; i < (a); ++i)
#define _rep(i, a, b) for(int i = (a); i < (b); ++i)
#define _forit(a, b) for(a::iterator it = b.begin(); it != b.end(); it++)


using namespace std;

double pie[10000];
int N = 0, F = 0;

bool che(double x) {
	int t = 0;
	_for(i, N)
		t += (int)(pie[i] / x);
	return t >= F;
}//检验当前分法是否可行

double getpie(double left, double right) {
	double t = (right + left) / 2;
	if (right - left < 0.00001) return t;
	if (che(t))
		return getpie(t, right);
	else
		return getpie(left, t);
}

int main()
{
	//freopen("input.txt", "r", stdin);
	int T = 0;
	cin >> T;
	while (T--) {
		double ave = 0;
		cin >> N >> F; F += 1;//获取蛋糕总个数和总人数
		_for(i, N) {
			cin >> pie[i];
			pie[i] = PI * pie[i] * pie[i];//直接把半径转化成面积
			ave += pie[i];
		}
		printf("%.4f\n", getpie(0, ave));
		//cout << getpie(0, ave / N) << endl;
	}
	return 0;
}

本人也是新手,也是在学习中,勿喷

转载请注明出处

欢迎有问题的小伙伴一起交流哦~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值