【BZOJ2426】【HAOI2010】工程选址

Description

某地区有m座煤矿,其中第i号矿每年产量为ai吨,现有火力发电厂一个,每年需用煤b吨,每年运行的固定费用(包括折旧费,不包括煤的运费)为h元,每吨原煤从第i号矿运到原有发电厂的运费为Ci0(i=1,2,…,m)。

 

现规划新建一个发电厂,m座煤矿每年开采的原煤将全部供给这两座发电厂。现有n个备选的厂址。若在第j号备选厂址建新厂,每年运行的固定费用为hj元。每吨原煤从第i号矿运到j号备选厂址的运费为Cij(i=1,2,…,m;j=1,2,…,n)。

 

试问:应把新厂厂址选取在何处?m座煤矿开采的原煤应如何分配给两个发电厂,才能使每年的总费用(发电厂运行费用与原煤运费之和)为最小。 

Input

第1行:      m  b  h  n

第2行:      a1  a2 …  am (0<=ai<=500, a1+a2+...+an>=b)

第3行:      h1  h2 …  hn (0<=hi<=100)

第4行:      C10 C20 … Cm0 (0<=Cij<=50)

第5行:      C11 C21 … Cm1

                              …   …

第n+4行:C1n C2n … Cmn

Output

第1行:新厂址编号,如果有多个编号满足要求,输出最小的。

第2行:总费用 

Sample Input

4 2 7 9
3 1 10 3
6 3 7 1 10 2 7 4 9
1 2 4 3
6 6 8 2
4 10 8 4
10 2 9 2
7 6 6 2
9 3 7 1
2 1 6 9
3 1 10 9
4 2 1 8
2 1 3 4

Sample Output

8
49

HINT

对于所有数据, n<=50, m<=50000, b<=10000 

题解

挺好的贪心题。

先假设把所有的煤都放到新工厂,然后对于每一个煤矿场都存一下新老费用的差,然后从小到大排序,,再用原来的费用加上老的费用,相当于你加上了老的而不用了新的,直到加到老厂有d吨煤为止。枚举一下每一个新厂就行了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=50010; 
const int inf=1e9;
int m,b,H,n;
struct node{
    int pos,num,cha;
}c3[N];
int c1[N],c2[55][N],a[N],h[55],ans1,ans=inf;
inline bool cmp(node a,node b){
    return a.cha<b.cha;
}
inline void cal(int pos){
    int cost=h[pos]+H;
    for(int i=1;i<=m;i++) {
        cost+=a[i]*c2[pos][i];
        c3[i].cha=c1[i]-c2[pos][i];
        c3[i].pos=i;
    }
    sort(c3+1,c3+m+1,cmp);
         
    int tmp=b;
    for(int i=1;i<=m;i++){
        if(tmp){
            if(tmp>=a[c3[i].pos]){
                cost+=a[c3[i].pos]*c3[i].cha;
                tmp-=a[c3[i].pos]; 
            }
            else cost+=tmp*c3[i].cha,tmp=0;
        }
        else break;
    }
    if(ans>cost){
        ans1=pos;
        ans=cost;
    }
}
int main(){
    scanf("%d%d%d%d",&m,&b,&H,&n);
    for(int i=1;i<=m;i++) scanf("%d",&a[i]);
     
    for(int i=1;i<=n;i++) scanf("%d",&h[i]);
     
    for(int i=1;i<=m;i++){
        scanf("%d",&c1[i]);
    }
     
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&c2[i][j]);
        }
    }
    for(int i=1;i<=n;i++){
        cal(i);
    }
    printf("%d\n%d\n",ans1,ans);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值