Wannafly挑战赛13 D-applese的生日

思路:首先要能看出, 对于每个蛋糕,如果分为k份,一定是平均分的;然后记录一下最小重量, 直接把这些蛋糕加到优先队列中,每次判断队列第一个蛋糕与最小值的比是否满足条件即可

Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
const ll mod = 998244353;
int n, m;
double T, k, mn;

struct D {
    double a, b;
    int num;
    D() {}
    D(double a, double b, int num) : a(a), b(b), num(num) {}
    bool operator < (const D &t) const {
        return b < t.b;
    }
};

int main() {
    while(~scanf("%lf %d", &T, &n)) {
        priority_queue<D> q;
        int ans = 0;
        mn = mod;
        for(int i = 0; i < n; i++) {
            scanf("%lf", &k);
            q.push(D(k, k, 1));
            mn = min(mn, k);
        }
        while(!q.empty()) {
            D d = q.top(); q.pop();
            if(mn / d.b >= T) break;
            d.num++;
            d.b = d.a / d.num;
            mn = min(d.b, mn);
            ans++;
            q.push(d);
        }
        printf("%d\n", ans);
    }
    return 0;
}

posted @ 2018-04-08 16:54  .ini  阅读(99)  评论(0编辑  收藏  举报