zoukankan      html  css  js  c++  java
  • UVALive 3635 Pie 切糕大师 二分

    题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的。

    做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又没说每个pie都要分完,分不完的留给工作人员吃嘛。

    代码:

    /*
    *  Author:      illuz <iilluzen[at]gmail.com>
    *  Blog:        http://blog.csdn.net/hcbbt
    *  File:        live3652.cpp
    *  Create Date: 2013-09-10 00:40:36
    *  Descripton:  binary, greedy 
    */
    
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    
    const int MAXN = 10010;
    const double PI = acos(-1.0);
    
    int n, f, t;
    double a[MAXN], Max;
    
    bool judge(double x) {
    	int sum = 0;
    	for (int i = 0; i < n; i++)
    		sum += a[i] / x;
    	if (sum >= f + 1) return true;
    	return false;
    }
    
    int main() {
    	scanf("%d", &t);
    	while (t--) {
    		scanf("%d%d", &n, &f);
    		for (int i = 0; i < n; i++) {
    			scanf("%lf", &a[i]);
    			a[i] = PI * a[i] * a[i];
    			Max = max(Max,  a[i]);
    		}
    		double low = 0, mid;
    		while (Max - low > 1e-5) {
    			mid = low + (Max - low) / 2;
    			if (judge(mid)) low = mid;
    			else Max = mid;
    		}
    		printf("%.4lf
    ", low);
    	}
    	return 0;
    }
    


  • 相关阅读:
    typescript-泛型-类型检查
    typescript-class-interface
    typescript-类class
    typescript-接口interface
    Oracle 密码过期
    VMware Redhat虚拟机扩容硬盘
    华硕 U系列电脑拆后盖注意事项
    VS + QT 出现 LNK2001 无法解析的外部符号 QMetaObject 的问题
    c++ _pFirstBlock == pHead
    c++ 套路多
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3312930.html
Copyright © 2011-2022 走看看