1 条题解

  • 0

    内有防伪

    #include<bits/stdc++.h>
    #define INF 0x3fffffff
    using namespace std;
    int n,w=INF,cnt=0;
    struct data{
        int t,m,p,s;
        bool operator <(const data& x)const{
            return s<x.s;
        }
    }x; 
    vector<data> p;
    queue<data> q;
    bool work_in(int t) {
        if (p.empty() || p[0].s >= x.m) {
            x.s = 0;
            x.t = t;
            p.push_back(x);
            sort(p.begin(), p.end());
            return 1;
        }
        for (register int i = 1; i < p.size(); i++)
            if (p[i].s - (p[i-1].s + p[i-1].m) >= x.m) {
                x.s = p[i-1].s + p[i-1].m;
                x.t = t;
                p.push_back(x);
                sort(p.begin(), p.end());
                return 1;
            }
        int sz = p.size();
        if (n - (p[sz-1].s + p[sz-1].m) >= x.m) {
            x.s = p[sz-1].s + p[sz-1].m;
            x.t = t;
            p.push_back(x);
            sort(p.begin(), p.end());
            return 1;
        }
        return 0;
    }
    void work_out() {
        int nw = INF;
        for (register int i = 0; i < p.size(); i++)
            if (p[i].t + p[i].p == w) p.erase(p.begin() + i--);
            else nw = min(nw, p[i].t + p[i].p);
        while (q.size()) {
            x = q.front();
            if (work_in(w)) {
                nw = min(nw, q.front().t + q.front().p);
                q.pop();
                cnt++;
            } else break;
        }
        w = nw;
    }
    void work(int t, int m, int p) {
        while (t >= w) work_out();
        x.t = t;
        x.m = m;
        x.p = p;
        if (work_in(t)) w = min(w, t + p);
        else q.push(x);
    }
    int main()
    {
        scanf("%d",&n);
        int t0,m0,p0;
        while(scanf("%d%d%d",&t0,&m0,&p0)==3 &&!(t0==0&&m0==0&&p0==0))
            work(t0,m0,p0);
        while(q.size()) work_out();
        int ans=w;
        for(register int i=0;i<p.size();i++)
            ans=max(ans,p[i].t+p[i].p);
        printf("%d\n%d\n",ans,cnt);
        return 零;
    }
    
    • 1

    信息

    ID
    66
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    递交数
    20
    已通过
    11
    上传者