• 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 


    Source

     
     
    正解:贪心
    解题报告:
      直接一遍贪心过去,跟上午考试的T1的apple几乎是一样的。
     
     
     1 //It is made by jump~
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <ctime>
     9 #include <vector>
    10 #include <queue>
    11 #include <map>
    12 #include <set>
    13 using namespace std;
    14 typedef long long LL;
    15 const int inf = (1<<30);
    16 const int MAXM = 50011;
    17 const int MAXN = 52;
    18 int m,b,hh,n;
    19 int ans,jilu;
    20 int mei[MAXM],h[MAXN];
    21 int c[MAXM][MAXN];
    22 struct node{
    23     int x,y,z;
    24     int num;
    25 }a[MAXM];
    26 inline bool cmp(node q,node qq){ return q.z<qq.z; }
    27 
    28 inline int getint()
    29 {
    30     int w=0,q=0; char c=getchar();
    31     while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
    32     while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
    33 }
    34 
    35 inline void work(){
    36     m=getint(); b=getint(); hh=getint();  n=getint(); int now,bb,j; ans=inf;
    37     for(int i=1;i<=m;i++) mei[i]=getint(); for(int i=1;i<=n;i++) h[i]=getint();
    38     for(int i=0;i<=n;i++) for(int j=1;j<=m;j++) c[j][i]=getint();
    39     for(int i=1;i<=n;i++) {
    40     now=h[i]+hh; bb=b;
    41     for(j=1;j<=m;j++) a[j].num=mei[j];
    42     for(j=1;j<=m;j++) a[j].y=c[j][i],a[j].x=c[j][0],a[j].z=a[j].x-a[j].y;
    43     sort(a+1,a+m+1,cmp);
    44     for(j=1;j<=m;j++) {
    45         if(a[j].num<=bb) {
    46         now+=a[j].num*a[j].x;
    47         bb-=a[j].num;
    48         }
    49         else { now+=bb*a[j].x,a[j].num-=bb; bb=0; break; }
    50     }
    51     for(;j<=m;j++) now+=a[j].num*a[j].y;
    52     if(now<ans) ans=now,jilu=i;
    53     }
    54     printf("%d
    %d",jilu,ans);
    55 }
    56 
    57 int main()
    58 {
    59     work();
    60     return 0;
    61 }
  • 相关阅读:
    此网页的安全性验证无效并且可能损坏的错误的解决方法
    fixSidebar简介与修正log
    Git可视化极简易教程 —— Git GUI使用方法
    windows平台快速搭建Linux(CentOS)
    CentOS在线安装Mysql5.7
    springboot集成mybatis(二)
    springboot测试、打包、部署
    springboot快速入门
    springboot集成mybatis(一)
    CentOS在线安装JDK
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5910400.html
Copyright © 2020-2023  润新知