码迷,mamicode.com
首页 > 其他好文 > 详细

codechef T4 IPC Trainers

时间:2017-07-12 10:12:00      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:strong   dia   min   大根堆   ring   ctr   整数   编程   fine   

 

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\n",ans);
    }
    return 0;
}
View Code

 

codechef T4 IPC Trainers

标签:strong   dia   min   大根堆   ring   ctr   整数   编程   fine   

原文地址:http://www.cnblogs.com/lyzuikeai/p/7153595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!