zoukankan      html  css  js  c++  java
  • codechef T4 IPC Trainers

    IPCTRAIN: 训练营教练
    题目描述 本次印度编程训练营(Indian Programming Camp,IPC)共请到了 N 名教练。训练营的日 程安排有 M 天,每天最多上一节课。第 i 名教练在第 Di 天到达,直到训练营结束才离开。第 i 名 教练希望上 Ti 节课。要是少上了课,那么教练会感到扎心,每少上一节,扎心值就会加 Si。 作为主办方,你希望最小化所有教练的扎心值之和。
    输入格式
    输入的第一行包含一个整数 T,代表测试数据的组数。接下来是 T 组数据。 每组数据的第一行包含两个整数 N 和 D。接下来 N 行,每行包含三个整数 Di,Ti,Si。
    输出格式
    对于每组数据,输出一行,包含一个整数,代表扎心值之和的最小值。
    数据范围和子任务 • 1 ≤ T ≤ 10 • 1 ≤ N,D,Si ≤ 105 • 1 ≤ Di,Ti ≤ D 子任务 1(40 分): • 1 leqN,D,Si ≤ 103
    子任务 2(60 分): • 无附加限制
    样例数据
    输入

    3

    2 3

    1 2 300

    2 2 100

    2 3

    1 1 100

    2 2 300

    2 3

    3 2 150

    1 1 200

    这道题呢我们先将所有教官都没得上课的扎心值统计起来为ans

    然后枚举时间 把符合条件的教官扔到大根堆里面 然后把还有课要交而扎心值又最大的教官拉出来让他去教 然后ans-x.w 这样一步步处理就好啦

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #define LL long long
    using namespace std;
    const int M=3e5+7;
    int read(){
        int ans=0,f=1,c=getchar();
        while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
        while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
        return ans*f;
    }
    int n,m,v,top;
    LL ans;
    struct note{int d,T,w;}e[M];
    bool cmp(note a,note b){return a.d>b.d;}
    struct node{
        int w,pos;
        bool operator <(const node&x)const {return w<x.w;}
    }; 
    priority_queue<node>q;
    int main()
    {
        v=read();
        while(v--){
            q=priority_queue<node>();
            n=read(); m=read(); 
            top=n; ans=0;
            for(int i=1;i<=n;i++) e[i].d=read(),e[i].T=read(),e[i].w=read(),ans=ans+(LL)e[i].T*e[i].w;
            sort(e+1,e+1+n,cmp); 
            for(int i=1;i<=m;i++){
                while(top&&e[top].d<=i) q.push((node){e[top].w,top}),top--; 
                node x=q.top();
                while(!e[x.pos].T){
                    q.pop();
                    if(q.empty()) break;
                    x=q.top();
                }
                if(q.empty()) continue;
                ans=ans-x.w; e[x.pos].T--; 
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    VUE 脚手架模板搭建
    defineProperty
    理解JS中的call、apply、bind方法
    Two-phase Termination模式
    打印样式设计
    浏览器内部工作原理
    Immutable Object模式
    怎么跳出MySQL的10个大坑
    控制台console
    整理的Java资源
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7153595.html
Copyright © 2011-2022 走看看