Код: Выделить всё
f+=c[i][j]*p[i][j];c одним аргументом аналог:
Код:
Код: Выделить всё
i++;
И оформите код тегом код. Выделив текст и нажав на знак - #Код: Выделить всё
void w_p()
{int i,j,h,l,k;
long int c_max;
k=0;
for (i=1;i<=Na;i++)
{
h=i*3+4;
for (j=1;j<=Nb;j++)
{
l=j*(n1+1)+n2-5;
gotoxy(l,h);
//Write(' ':n1);
//cout<<setw(7)<<" ";
if (p[i][j]>0)
{
k++;
Print(l-trunc(log(p[i][j])/log(10))+5,h,p[i][j]);
}
else if (p[i][j]==0)
{
Print(l+n1-2,h,p[i][j]);
k++;
}}}
while (a_b=true)
{k++;}
if (k>Na+Nb-1) PrintS(40,1,"k > n+m-1");
}Код: Выделить всё
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int trunc(int x) //Аналог функции trunc() в паскале
{
float a;
if(x % x == 0)
x = x;
else{
a = x % x;
x = x - a;
}
return x;
}
int _tmain(int argc, _TCHAR* argv[])
{
system("cls");
cout
Смотрите:Код: Выделить всё
...
coutКод: Выделить всё
// transport.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const
int N=6;
int n1=7;
int n2=7;
long int Sa=0;
long int Sb=0;
typedef long int predpr[N];
typedef long int rasp[N][N];
predpr A,B,alfa,betta,B_d,x;
rasp c,p;
long int f,f0,x_min;
unsigned char Nt,x_p,r,r_min,ki,kj,Na,Nb,h,l,i,j;
char d;
unsigned char u[N*N];
void gotoxy(int x, int y)// Аналог функции gotoxy в Паскале
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int trunc(int x) //Аналог функции trunc() в паскале
{float a;
if (x%x==0) {x=x;}
else
{a=x%x;
x=x-a;}
return x;
}
void Nul(predpr a)
{unsigned char i;
{for (i=1;iКод: Выделить всё
Program transportnaj_zadatsha;
Uses Crt;
Label l1;
Const N=6;
n1=7; n2=7;
Sa:longint=0;
Sb:longint=0;
Type predpr=Array [1..N] of longint;
rasp=Array [1..N,1..N] of longint;
Var A,B,alfa,betta,B_d,x:predpr;
c,p:rasp;
f,f0,x_min,Sp:longint;
Nt,x_p,r,r_min,ki,kj,Na,Nb,h,l,i,j:byte;
d:char;
u:Array[1..N*N] of byte;
Procedure Nul (var a:predpr);
var i:byte;
Begin
for i:=1 to N do a[i]:=0;
End;
Procedure PrintS (x,y:byte; s:string);
Begin
GotoXY(x,y);
Write(s);
End;
Procedure Print (x,y:byte;a:longint);
Begin
GotoXY(x,y); Write(a);
End;
Procedure Tabl;
Begin
ClrScr;
h:=6+Na*3;
l:=14+Nb*7;
GotoXY(1,3);
for i:=1 to Na+1 do begin
GotoXY(1,i*3+2);
end;
for i:=1 to Na do begin
GotoXY(5,i*3+3);
Write('A',i);
end;
for i:=1 to Nb do begin
GotoXY(i*(n1+1)+n2-2,3);
Write('B',i);
end;
l:=Nb*(n1+1)+n2+3;
h:=Na*3+6;
PrintS(4,3,'\Bj');
PrintS(4,4,'Ai\');
PrintS(l,4,'Ui');
PrintS(3,h,' Vj');
End;
Function FF:longint;
var i,j:integer;
f:longint;
Begin
f:=0;
for i:=1 to Na do
for j:=1 to Nb do
if p[i,j]>0 then
// inc(f,c[i,j]*p[i,j]);
f:=f+c[i,j]*p[i,j];
i:=i+1;
j:=j+1;
GotoXY(65,Nt+2);
Write('F',Nt,'=',f);
FF:=f;
End;
Function a_b:boolean;
var k,i,j:byte;
Z_a,Z_b:predpr;
d:boolean;
Begin
Nul(Z_a);
Nul(Z_b);
alfa[1]:=0;
Z_a[1]:=1;
k:=1;
Repeat
d:=1=1;
for i:=1 to Na do
if Z_a[i]=1 then
for j:=1 to Nb do
if (p[i,j]>-1) and (Z_b[j]=0) then begin
Z_b[j]:=1;
betta[j]:=c[i,j]-alfa[i];
inc(k);
d:=1=2;
end;
for i:=1 to Nb do
if Z_b[i]=1 then
for j:=1 to Na do
if (p[j,i]>-1) and (Z_a[j]=0) then begin
Z_a[j]:=1;
alfa[j]:=c[j,i]-betta[i];
inc(k);
d:=1=2;
end;
Until (k=Na+Nb) or d;
if d then begin
i:=1;
While Z_a[i]=1 do inc(i);
j:=1;
While Z_b[j]=0 do inc(j);
p[i,j]:=0;
Print((j+1)*(n1+1)+n2-8,i*3+4,p[i,j]);
end;
a_b:=d;
End;
Function kkk(var ki,kj:byte):integer;
var i,j:byte;
k,k_min:integer;
b:boolean;
Begin
b:=1=1;
for i:=1 to Na do
for j:=1 to Nb do
if p[i,j]=-1 then begin
k:=c[i,j]-alfa[i]-betta[j];
if b then begin
b:=1=2;
ki:=i; kj:=j; k_min:=k;
end else
if k1 then begin dec(i);
Delete(s,i,1);
Write(chr(8),' ',chr(8));
end;
end;
j:=WhereX;
GotoXY(60,1);
ClrEOL;
GotoXY(j,1);
Until (ord(c)=13) and (i0 then begin
inc(k);
Print(l-trunc(ln(p[i,j])/ln(10))+5,h,p[i,j]);
end
else if p[i,j]=0 then begin
Print(l+n1-2,h,p[i,j]);
inc(k);
end;
end;
end;
While a_b do inc(k);
if k>Na+Nb-1 then PrintS(40,1,'k > n+m-1');
End;
Procedure div_mod(c:byte; var a,b:byte);
Begin
b:=c mod Nb; a:=c div Nb +1;
if b=0 then begin
b:=Nb; dec(a);
end;
End;
Procedure Rek(Xi,Yi:byte; var z:boolean; var c:byte);
var i,j:byte;
Begin
z:=1=2;
Case c of
1: for i:=1 to Na do
if iXi then
if p[i,Yi]>-1 then begin
if u[(i-1)*Nb+Yi]=0 then begin
u[(Xi-1)*Nb+Yi]:=(i-1)*Nb+Yi;
c:=2;
Rek(i,Yi,z,c);
if z then exit;
end;
end
else if (i=ki) and (Yi=kj) then begin
u[(Xi-1)*Nb+Yi]:=(ki-1)*Nb+kj;
z:=not z;
exit;
end;
2: for i:=1 to Nb do
if iYi then
if p[Xi,i]>-1 then begin
if u[(Xi-1)*Nb+i]=0 then begin
u[(Xi-1)*Nb+Yi]:=(Xi-1)*Nb+i;
c:=1;
Rek(Xi,i,z,c);
if z then exit;
end;
end
else if (Xi=ki) and (i=kj) then begin
u[(Xi-1)*Nb+Yi]:=(ki-1)*Nb+kj;
z:=not z;
exit;
end;
end;
u[(Xi-1)*Nb+Yi]:=0;
c:=c mod 2 +1;
End;
Procedure kontur;
var i,j,k,mi,mj,l:byte;
z:boolean;
p_m:longint;
Begin
for i:=1 to N*N do u[i]:=0;
l:=1;
Rek(ki,kj,z,l);
i:=ki; j:=kj;
k:=u[(i-1)*Nb+j];
div_mod(k,i,j);
mi:=i; mj:=j; l:=1;
Repeat
inc(l);
k:=u[(i-1)*Nb+j];
div_mod(k,i,j);
if l mod 2=1 then
if p[i,j]1) and (Na1) and (NbSb then begin
inc(Nb);
B[Nb]:=Sa-Sb;
for i:=1 to Na do c[i,Nb]:=0;
end else begin
inc(Na);
A[Na]:=Sb-Sa;
for i:=1 to Nb do c[Na,i]:=0;
end;
Tabl;
for i:=1 to Na do
for j:=1 to Nb do Print((n1+1)*j+n2-4,i*3+3,c[i,j]);
for i:=1 to Na do
Print(n2-trunc(ln(A[i])/ln(10)),i*3+4,A[i]);
for i:=1 to Nb do
Print(n2+i*(n1+1)-trunc(ln(B[i])/ln(10)),4,B[i]);
end;
(************** c?????????? ???????? ????? ****************)
for i:=1 to Nb do B_d[i]:=B[i];
for i:=1 to Na do begin
for j:=1 to Nb do x[j]:=j;
for j:=1 to Nb-1 do begin
x_min:=c[i,x[j]];
r_min:=j;
for r:= j+1 to Nb do
if (x_min>c[i,x[r]]) or
((x_min=c[i,x[r]]) and (B[x[r]]>b[x[r_min]])) then
begin
x_min :=c[i,x[r]];
r_min:=r;
end;
x_p:=x[r_min];
x[r_min]:=x[j];
x[j]:=x_p;
end;
Sp:=0;
for j:=1 to Nb do begin
p[i,x[j]]:=B_d[x[j]];
if p[i,x[j]]>A[i]-Sp then p[i,x[j]]:=A[i]-Sp;
inc(Sp,p[i,x[j]]);
dec(B_d[x[j]],p[i,x[j]]);
end;
end;
(***********************************************************)
for i:=1 to Na do
for j:=1 to Nb do if p[i,j]=0 then p[i,j]:=-1;
W_p;
f:=FF; f0:=F;
While a_b do;
for i:=1 to Na do Print(l+1,i*3+3,alfa[i]);
for i:=1 to Nb do Print(i*(n1+1)+n2-4,h,betta[i]);
Pauza;
(******* ??????????? ??????????? ????? ? ???????????? ******)
While kkk(ki,kj)