nowcoder80D applese的生日

题意:有n个蛋糕,现在要切蛋糕,蛋糕不能拼接,要使得最小的蛋糕不能小于最大的蛋糕的T倍,问最少切多少刀

题解:对于一个蛋糕,一定是平均切,否则会造成一块大一块小,所以对每块蛋糕放入优先队列,每次取出队头多切一刀

#include <bits/stdc++.h>
#define maxn 100010
#define INF 0x3f3f3f3f
using namespace std;
struct node{
    double x;int y;
}a[maxn];
struct cmp{
    bool operator()(node aa,node bb){
        return aa.x/aa.y < bb.x/bb.y;
    }
};
priority_queue<node, vector<node >, cmp>q;
int main(){
    double T, t, mi = 1e18;
    int n, ans = 0;
    scanf("%lf%d", &T, &n);
    for(int i=0;i<n;i++){
        scanf("%lf", &t);
        q.push((node){t, 1});
        mi = min(t, mi);
    }
    while(!q.empty()){
        node t = q.top();q.pop();
        if(mi >= t.x/t.y*T) break;
        ans++;
        q.push((node ){t.x, t.y+1});
        mi = min(mi, t.x/(t.y+1));
    }
    cout<<ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/Noevon/p/8734884.html