翻译程序。c++翻成Pascal
#include<stdio.h>#include<string.h>intc[4][4],f[4][4];boolb[4];intans;voidinit(){inta...
#include<stdio.h>
#include<string.h>
int c[4][4],f[4][4];
bool b[4];
int ans;
void init()
{
int a,b;
scanf("%d%d",&a,&b);
c[0][1]=a;c[1][3]=a;
c[0][2]=b;c[2][3]=b;
}
bool find(int x)
{
if(x==3)return true;
for(int i=0;i<4;i++)
{
if(f[x][i]<c[x][i]&&!b[i])
{
b[i]=true;
if(find(i))
{
f[x][i]++;f[i][x]--;
return true;
}
}
}
return false;
}
void process()
{
ans=0;
memset(b,false,sizeof(b));
b[0]=true;
while(find(0))
{
memset(b,false,sizeof(b));
b[0]=true;
ans++;
}
}
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
init();
process();
printf("%d\n",ans);
}
是网络流做a+b的
麻烦大牛们帮我翻译下
要是有Pascal的程序直接贴上来也行 展开
#include<string.h>
int c[4][4],f[4][4];
bool b[4];
int ans;
void init()
{
int a,b;
scanf("%d%d",&a,&b);
c[0][1]=a;c[1][3]=a;
c[0][2]=b;c[2][3]=b;
}
bool find(int x)
{
if(x==3)return true;
for(int i=0;i<4;i++)
{
if(f[x][i]<c[x][i]&&!b[i])
{
b[i]=true;
if(find(i))
{
f[x][i]++;f[i][x]--;
return true;
}
}
}
return false;
}
void process()
{
ans=0;
memset(b,false,sizeof(b));
b[0]=true;
while(find(0))
{
memset(b,false,sizeof(b));
b[0]=true;
ans++;
}
}
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
init();
process();
printf("%d\n",ans);
}
是网络流做a+b的
麻烦大牛们帮我翻译下
要是有Pascal的程序直接贴上来也行 展开
1个回答
展开全部
给你翻译了~~ 给分吧~~
var
c,f:array[1..4,1..4] of integer;
b:array[1..4] of boolean;
ans:integer;
procedure init;
var
a,b:integer;
begin
readln(a,b);
c[1,2]:=a;c[2,4]:=a;
c[1,3]:=b;c[3,4]:=b;
end;
function find(x:integer):boolean;
var i:integer;
begin
if x=4 then
begin
find:=true;
exit;
end;
for i:=1 to 4 do
begin
if (f[x,i]<c[x,i]) and (not b[i]) then
begin
b[i]:=true;
if find(i) then
begin
f[x,i]:=f[x,i]+1;
f[i,x]:=f[i,x]-1;
find:=true;
exit;
end;
end;
end;
find:=false;
end;
procedure process;
begin
ans:=0;
fillchar(b,sizeof(b),false);
b[1]:=true;
while (find(1)) do
begin
fillchar(b,sizeof(b),false);
b[1]:=true;
inc(ans);
end;
end;
///////////////////////////////////////
begin
assign(input,"a.in");
assign(output,"a.out");
reset(input);
rewrite(output);
init;
process;
close(input);
close(output);
end.
///////////////////////////////////////
var
c,f:array[1..4,1..4] of integer;
b:array[1..4] of boolean;
ans:integer;
procedure init;
var
a,b:integer;
begin
readln(a,b);
c[1,2]:=a;c[2,4]:=a;
c[1,3]:=b;c[3,4]:=b;
end;
function find(x:integer):boolean;
var i:integer;
begin
if x=4 then
begin
find:=true;
exit;
end;
for i:=1 to 4 do
begin
if (f[x,i]<c[x,i]) and (not b[i]) then
begin
b[i]:=true;
if find(i) then
begin
f[x,i]:=f[x,i]+1;
f[i,x]:=f[i,x]-1;
find:=true;
exit;
end;
end;
end;
find:=false;
end;
procedure process;
begin
ans:=0;
fillchar(b,sizeof(b),false);
b[1]:=true;
while (find(1)) do
begin
fillchar(b,sizeof(b),false);
b[1]:=true;
inc(ans);
end;
end;
///////////////////////////////////////
begin
assign(input,"a.in");
assign(output,"a.out");
reset(input);
rewrite(output);
init;
process;
close(input);
close(output);
end.
///////////////////////////////////////
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询