⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 napkin.pas

📁 PASCAL光盘资料PASCAL光盘资料PASCAL光盘资料
💻 PAS
字号:
program napkin(input,output);
const maxn=30;
type arrtype=array[-maxn..maxn] of integer;
var
   i,j,totalday,m,n,p,f,s,current,day:integer;
   allneed,allbuy,cost,sum,restslow,fast,mincost:integer;
   finish:boolean;
   need,fromslow,fromfast,buy,temp:arrtype;
   result:array[1..3] of arrtype;
begin
   assign(input,'napkin.in');
   assign(output,'napkin.out');
   reset(input);
   rewrite(output);
   readln(totalday);
   for i:=1 to totalday do read(need[i]);readln;
   readln(p,m,f,n,s);
   allneed:=0;
   for i:=1 to totalday do allneed:=allneed+need[i];
   finish:=true;allbuy:=allneed;mincost:=maxint;
   while finish do
     begin
       sum:=allbuy;
       for i:=1 to totalday do
           if sum>need[i]
             then begin buy[i]:=need[i];sum:=sum-need[i] end
             else begin buy[i]:=sum;sum:=sum-buy[i] end;
       for i:=-totalday to totalday do fromslow[i]:=0;
       for i:=-totalday to totalday do fromfast[i]:=0;
       restslow:=0;temp:=need;
       for i:=1 to totalday do
         begin
           restslow:=restslow+temp[i-n];
           if need[i]>buy[i] then
             begin
               if restslow>need[i]-buy[i]
                 then fromslow[i]:=need[i]-buy[i]
                 else fromslow[i]:=restslow;
               restslow:=restslow-fromslow[i];
               j:=i-m;
               fast:=need[i]-buy[i]-fromslow[i];
               fromfast[i]:=fast;
               while(j>i-n) and (fast>0) do
                 if temp[j]>=fast
                   then begin temp[j]:=temp[j]-fast;fast:=0 end
                   else begin fast:=fast-temp[j];temp[j]:=0;j:=j-1 end;
                 if (j<=i-n) and (fast>0) then finish:=false
             end;
         end;
           if finish then
             begin cost:=0;
                   for j:=1 to totalday do
                       cost:=cost+buy[j]*p+fromfast[j]*f+fromslow[j]*s;
                   if cost<mincost then
                     begin
                        mincost:=cost;
                        result[1]:=buy;
                        result[2]:=fromfast;
                        result[3]:=fromslow;
                     end
             end;
             allbuy:=allbuy-1
     end;
   fromfast:=result[2];fromslow:=result[3];temp:=need;
   for i:=2 to 3 do
     for j:=1 to totalday do result[i,j]:=0;
   for j:=totalday downto m do
     begin
       current:=fromfast[j];day:=j-m;
       while current>0 do
         begin
           if temp[day]>=current
             then begin result[2,day]:=result[2,day]+current;
                        temp[day]:=temp[day]-current;
                        current:=0 end
             else begin result[2,day]:=result[2,day]+temp[day];
                        current:=current-temp[day];
                        temp[day]:=0;day:=day-1 end;
         end;
     end;
   for j:=n to totalday do
     begin
       current:=fromslow[j];day:=1;
       while current>0 do
         begin
           if temp[day]>=current
             then begin result[3,day]:=result[3,day]+current;
                        temp[day]:=temp[day]-current;
                        current:=0 end
             else begin result[3,day]:=result[3,day]+temp[day];
                        current:=current-temp[day];
                        temp[day]:=0;day:=day+1 end;
         end;
     end;
   writeln(mincost);
   for i:=1 to totalday do
     begin
       write(need[i]:10);
       for j:=1 to 3 do write(result[j,i]:10);
       writeln(fromfast[i]:10,fromslow[i]:10)
     end;
  close(input);
  close(output)
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -