CF1132D Stressful Training

简介: CF1132D Stressful Training

题目: CF1132D Stressful Training ,哈哈,我们今天来看一道稍微复杂一点的题嘛,这是选自codeforce上的一道题,好了,我们一起来看看题意吧:

考虑到直接复制题目,或者截屏的方式不是很方便阅读,我就把直接题目链接放下面!

题目传送门: CF1132D Stressful Training

思路:

这道题思路就是采用贪心和二分的思想!!

我们先按照电脑能撑的时间时间从小到大排序,用一个优先队列来维护即可,我们每次判断队头是否符合条件即可,具体的直接看代码吧

我们来看看成功AC的代码吧:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a[1000010],b[1000010];
ll l=0,r=2e12;
struct node{
    ll a,b;
    double c;
    bool operator < (const node &x)const {
        return c>x.c;
    }
};
priority_queue<node> q;
int check(ll x){
    while(!q.empty()) q.pop();
    for(int i=1;i<=n;i++){
        if(a[i]*1.0/b[i]<k){
            q.push({a[i],b[i],a[i]*1.0/b[i]});
        }
    }
    if(q.empty()) return 1; //若队列为空,说明当前x 取大了,因为 所有电脑都能在k分钟内不关机
    for(int i=0;i<k;i++){
        node t = q.top();   q.pop();
        t.a+=x;
        if(t.c<i) return 0;//这台电脑已经没电了
        t.c=t.a*1.0/t.b;
        if(t.a*1.0/t.b<k){
            q.push(t);
        }
        if(q.empty()) return 1;
    }
    return 1;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    while(l<r){
        ll mid=l+r>>1;
        if(check(mid)) r=mid;
        else l=mid+1;
    }
    if(l==2e12)
        cout<<-1<<"\n";
    else cout<<l<<"\n";
    return 0;
}


相关文章
Warning: Can save best model only with val_acc available, skipping
本文解决了在使用DenseNet网络结构保存最优模型时出现的"Warning: Can save best model only with val_acc available, skipping"问题,方法是将`ModelCheckpoint`回调函数中的`monitor`参数值从`val_acc`改为`val_accuracy`。
|
6月前
|
机器学习/深度学习 人工智能
【CatBoost报错解决】CatBoostError: Bad value for num feature[non default doc idx=0,feature idx=19]=
【CatBoost报错解决】CatBoostError: Bad value for num feature[non default doc idx=0,feature idx=19]=
beamManagement(四)connected mode UL training
上行方向beam训练也有针对PUSCH 和PUCCH的两种机制,先看PUSCH。UE完成初始接入后,上行方向上主要通过Sounding RS(SRS)进行波束训练,SRS配置参数中,usage 设为 beamManagement时,表示用于波束管理的SRS。用于波束管理的SRS resourceset个数,每个resourceset中SRS resource个数和UE能力有关,在38306中定义。
|
机器学习/深度学习 人工智能
CF788A Functions again
CF788A Functions again
67 0
|
JSON 数据格式
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
517 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
|
TensorFlow 算法框架/工具
ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D
ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D
179 0
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
|
算法框架/工具 Windows
成功解决_catboost.CatBoostError: Invalid cat_features[4] = 8 value: index must be < 8.
成功解决_catboost.CatBoostError: Invalid cat_features[4] = 8 value: index must be < 8.