UVALive 3635-Pie-二分

给n个面积的蛋糕,要求每个人最后只拿一个等面积的圆蛋糕,问最后每个人能拿到的最大的面积是多少?

所有蛋糕都是完整的圆以及  每个人拥有圆形蛋糕的 面积与他人一样 

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33697


二分  答案X;

对于X

把所有原有的蛋糕去除X 即可得到可以分出来的个数(取整),不断逼近答案;

注意用eps控制精度

ac代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std;
const int inf =2147483640;
const double eps=0.000001;
int min(int a,int b)
{return a<b?a:b;}
double tm[10005];
int n,m;
const double pi=acos(-1);
int main()
{ 
double  ok(double x);
	int  t;
	cin>>t;
	while(t--)
	{
		int i;
		scanf("%d%d",&n,&m);
		m++;
		double maxx=0;
		double rr;
		for (i=1;i<=n;i++)
		{
			scanf("%lf",&rr);
			tm[i]=rr*rr*pi;
			if (tm[i]>maxx)
				maxx=tm[i];
		}  
		double l=0;
		double r=maxx;
		while(eps<r-l )
		{
		 
			if (r-l<=eps)
			{
				if (!ok(r))  r=l;
				break;
			}
			double mid=(l+r)/2;
			if (ok(mid))
				l=mid;
			else
				r=mid-eps;
			
		}

		printf("%.4lf\n",r);
	}
	return 0; 
} 
double  ok(double x)
{
	int  sum=0;
 	for (int it=1;it<=n;it++) 
		sum+=int(tm[it]/x);  
	if (sum>=m)
		return 1;
	else
		return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值