HDU 5859 Captain is coding

有两场比赛同时开始,一共有 N 道题,第一场的结束时间为X,第二场的结束时间为 Y ,要求AK,初始能力值为W,刷一次板子可以使能力值提高 Z ,第i题要求能力值 Ci ,A了之后能力值会提高 Di ,且只属于一场比赛(必须在 X Y之前A掉),每单位时间只能A一道题或刷一次板子,求最短AK时间或输出无解。
0<N<=1000,0<X,Y<=1000000,0<Z<=1000,0<=W<=109,0<=Ci<=109,0<=Di<=1000

二分完成时间判是否可行.不妨设A的deadline比B的deadline短,对于一次判断内,由于总时间固定,两类任务完成的总时间固定,则可用来练习的时间也固定,首先找到可完成的收益最大的 A类任务,若找不到则在B里找,此时若B类的收益还不如去练习,而且练习时间有剩余的话,就先去练习.A类任务若能做则不需要考虑收益,因为要优先保证A的deadline,先练后练对最优解无影响.

和chk一起做的

看起来很有意思的题, btw,模拟工厂也很有意思

贪心+二分

#include <set>
#include <ctime>
#include <queue>
#include <cstdio>
#include <bitset>
#include <cctype>
#include <bitset>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf (1<<30)
#define INF (1ll<<62)
#define fi first
#define se second
#define rep(x,s,t) for(register int x=s,t_=t;x<t_;++x)
#define per(x,s,t) for(register int x=t-1,s_=s;x>=s_;--x)
#define travel(x) for(int I=last[x],to;I&&(to=e[I].to);I=e[I].nxt)
#define prt(x) cout<<#x<<":"<<x<<" "
#define prtn(x) cout<<#x<<":"<<x<<endl
#define pb(x) push_back(x)
#define hash asfmaljkg
#define rank asfjhgskjf
#define y1 asggnja
#define y2 slfvm
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
template<class T>void sc(T &x){
    int f=1;char c;x=0;
    while(c=getchar(),c<48)if(c=='-')f=-1;
    do x=x*10+(c^48);
    while(c=getchar(),c>47);
    x*=f;
}
template<class T>void nt(T x){
    if(!x)return;
    nt(x/10);
    putchar(x%10+'0');
}
template<class T>void pt(T x){
    if(x<0)putchar('-'),x=-x;
    if(!x)putchar('0');
    else nt(x);
}
template<class T>void ptn(T x){
    pt(x);putchar('\n');
}
template<class T>void pts(T x){
    pt(x);putchar(' ');
}
template<class T>inline void Max(T &x,T y){if(x<y)x=y;}
template<class T>inline void Min(T &x,T y){if(x>y)x=y;}

int n,X,Y,Wp,Z;
const int maxn=1006;
struct node{
    int c,d;
    bool operator <(const node&a)const{
        return d<a.d;
    }
}A[2][maxn];
int cnt[2],Lim[2];
bool cmp(node a,node b){
    return a.c<b.c;
}

int fi,se,pre;

void input(){
    sc(n);sc(Lim[0]);sc(Lim[1]);sc(Wp);sc(Z);
    cnt[0]=cnt[1]=0;
    rep(i,0,n){
        int c,d;char s[4];
        sc(c);sc(d);scanf("%s",s);
        if(s[0]=='A')A[0][cnt[0]++]=(node){c,d};
        else A[1][cnt[1]++]=(node){c,d};
    }
    fi=Lim[0]>Lim[1]?0:1;
    se=fi^1;
}

bool judge(){
    int rem=Lim[fi]-n;
    if(rem<0||cnt[se]>Lim[se])return false;
    int top=0,tp=0;

    priority_queue<node>Q;
    ll tt=0,W=Wp;

    while(tp<cnt[fi]&&A[fi][tp].c<=W){
            Q.push(A[fi][tp]);
            tp++;
        }

    while(top<cnt[se]){
        if(A[se][top].c<=W){
            W+=A[se][top].d;
            top++;
        }
        else{
            if(!Q.empty()&&rem){
                node p=Q.top();
                if(p.d>=Z){
                    Q.pop();
                    W+=p.d;
                }
                else{
                    int tar=tp<cnt[fi]?min(A[se][top].c,A[fi][tp].c):A[se][top].c;
                    int nd=1ll*(tar-W+Z-1)/Z;
                    nd=min(nd,rem);
                    rem-=nd;
                    W+=1ll*Z*nd;
                    tt+=nd-1;
                }
            }
            else if(!Q.empty()){
                node p=Q.top();Q.pop();
                W+=p.d;
            }
            else if(rem){
                int tar=tp<cnt[fi]?min(A[se][top].c,A[fi][tp].c):A[se][top].c;
                int nd=1ll*(tar-W+Z-1)/Z;
                nd=min(nd,rem);
                rem-=nd;
                W+=1ll*Z*nd;
                tt+=nd-1;
            }
            else return false;
        }
        while(tp<cnt[fi]&&A[fi][tp].c<=W){
            Q.push(A[fi][tp]);
            tp++;
        }
        tt++;
        if(tt>Lim[se])return false;
    }
    while(!Q.empty()){
        node p=Q.top();Q.pop();
        W+=p.d;
    }
    while(tp<cnt[fi]){
        if(A[fi][tp].c<=W){
            W+=A[fi][tp].d;
            tp++;
        }
        else if(rem){
            int nd=(A[fi][tp].c-W+Z-1)/Z;
            nd=min(nd,rem);
            rem-=nd;
            W+=1ll*Z*nd;
        }
        else return false;
    }
    return true;
}

void solve(){
    input();pre=cnt[fi];

    sort(A[fi],A[fi]+cnt[fi],cmp);
    sort(A[se],A[se]+cnt[se],cmp);

    int a=Lim[fi],b=Lim[se];
    int l=n,r=Lim[fi],res=-1;
    while(l<=r){
        int mid=l+r>>1;
        Lim[fi]=min(a,mid);
        Lim[se]=min(b,mid);
        if(judge()){
            res=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    if(res==-1)puts("Poor Captain Chen");
    else ptn(res);
}

int main(){
//  freopen("pro.in","r",stdin);
//  freopen("chk.out","w",stdout);
    int cas;sc(cas);
    int kas=0;
    while(cas--){
        ++kas;
        solve();
    }
    return 0;
}
基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip 个人大四的毕业设计、课程设计、作业、经导师指导并认可通过的高分设计项目,评审平均分达96.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。 [资源说明] 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设或者课设、作业,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96.5分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),供学习参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值