zoukankan      html  css  js  c++  java
  • bzoj2426

    稍微列个式子就知道是贪心

     1 var w,h,c,a,f:array[0..50010] of longint;
     2     m,b,h0,n,i,p,j,x,ans,s:longint;
     3 
     4 procedure swap(var a,b:longint);
     5   var c:longint;
     6   begin
     7     c:=a;
     8     a:=b;
     9     b:=c;
    10   end;
    11 
    12 procedure sort(l,r: longint);
    13   var i,j,x,y: longint;
    14   begin
    15     i:=l;
    16     j:=r;
    17     x:=a[(l+r) div 2];
    18     repeat
    19       while a[i]<x do inc(i);
    20       while x<a[j] do dec(j);
    21       if not(i>j) then
    22       begin
    23         swap(a[i],a[j]);
    24         swap(f[i],f[j]);
    25         inc(i);
    26         j:=j-1;
    27       end;
    28     until i>j;
    29     if l<j then sort(l,j);
    30     if i<r then sort(i,r);
    31   end;
    32 
    33 begin
    34   readln(m,b,h0,n);
    35   for i:=1 to m do
    36     read(w[i]);
    37   for i:=1 to n do
    38     read(h[i]);
    39   for i:=1 to m do
    40     read(c[i]);
    41   ans:=2147483647;
    42   for i:=1 to n do
    43   begin
    44     s:=h0+h[i];
    45     for j:=1 to m do
    46     begin
    47       read(x);
    48       a[j]:=c[j]-x;
    49       f[j]:=j;
    50       s:=s+w[j]*x;
    51     end;
    52     sort(1,m);
    53     x:=0;
    54     for j:=1 to m do
    55       if x+w[f[j]]<b then
    56       begin
    57         x:=x+w[f[j]];
    58         s:=s+a[j]*w[f[j]];
    59       end
    60       else begin
    61         s:=s+a[j]*(b-x);
    62         break;
    63       end;
    64     if ans>s then
    65     begin
    66       p:=i;
    67       ans:=s;
    68     end;
    69   end;
    70   writeln(p);
    71   writeln(ans);
    72 end.
    View Code
  • 相关阅读:
    软件乘法实现
    矩阵连乘求解优化
    { 控件动态创建的堆与栈 }
    digital clock based C
    C++初探
    C语言语法教程-链表
    EF Core 实现读写分离的最佳方案
    Windows Terminal 安装及美化
    .netcore centos环境搭建实战
    AutoMapper.RegExtension 介绍
  • 原文地址:https://www.cnblogs.com/phile/p/4473017.html
Copyright © 2011-2022 走看看