UVALive - 3635 - Pie(二分)

原创 2016年08月30日 18:45:40

题意:有F + 1(1 <= F <= 10000)个人分N(1 <= N <= 10000)个圆形派,每个人得到的派面积相同,且必须是一整块(不能够两个甚至多个派拼在一起),求每个人最多能得到多大面积的派。(误差最多到0.001)


因为答案是小数类型的,并且N高达10000,故不可暴力枚举。

可以二分枚举最大面积,然后检查是否切出来派的总个数大于等于F + 1。

(判相等时不可直接判相等,需要加精度控制)


#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#define fin freopen("in.txt", "r", stdin)
#define fout freopen("out.txt", "w", stdout)
#define pr(x) cout << #x << " : " << x << "   "
#define prln(x) cout << #x << " : " << x << endl
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-6;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const ll MOD = 1e9 + 7;
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;

int T, n, f;
double a[MAXT];

bool judge(double area){
    int sum = 0;
    for(int i = 0; i < n; ++i)  sum += int(a[i] / area);
    return sum >= f;
}

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] = a[i] * a[i] * pi;
        }
        ++f;
        double l = 0.0, r = *max_element(a, a + n);
        while(l + EPS < r){
            double mid = (l + r) / 2;
            if(judge(mid))  l = mid;
            else  r = mid;
        }
        printf("%.4lf\n", l);
    }
    return 0;
}



uva - 12097 - Pie(二分法)

题意:有f+1个人来分N个圆形派,每个人得到的必须是一块整派,而不是几块拼在一起的。要求得到的派面积要相同。求每个人最多得到多大面积的派。 方法:采用二分法,转化为“是否可以让每个人得到一块面积为x的...

【二分答案】【POJ3122】【Northwestern Europe 2006】Pie

Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10629   Accepted:...

Leonardo's Notebook [NWERC 2006,LA 3641]

Leonardo’s Notebook

UVALive 3635 Pie 【二分】

Pie Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

UVALive - 3635 Pie(二分答案查找)

点击打开题目链接 Time limit: 1 second My birthday is coming up and traditionally I'm serving pie. Not ju...

LA 3635 - Pie 【二分】

Regionals 2006 >> Europe - Northwestern 3635 - PieTime limit: 3.000 seconds My birthday is coming ...

派(Pie,NWERC 2006,LA 3635)

派(Pie,NWERC 2006,LA 3635)

HDU1969:Pie(二分)

Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, n...

HDOJ 1969 Pie (二分)

HDOJ 1969 Pie (二分) 题意: 要办生日Party,有 N个馅饼,有 F个朋友,接下来是 n 个馅饼的 半径。然后,分馅饼,注意自己也要(总人数为 F+ 1)大家都要一样...

HDOJ 1969 Pie(二分)

Pie Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UVALive - 3635 - Pie(二分)
举报原因:
原因补充:

(最多只允许输入30个字)