# 娱乐向——a+b 的数种写法

542人阅读 评论(0)

## 1.正常写法

var
a,b:longint;
begin
writeln(a+b);
end.

## 2.随机数

var
a,b,c:longint;
begin
randomize;
while true do
begin
c:=random(100000000);
if c=a+b
then
begin
writeln(c);
halt;
end;
end;
end.

## 3.深搜

var
f,l:array[1..10] of longint;
i,j,k,n,m,a,b,ans:longint;
procedure dfs(dep:longint);
var
i,j,k:longint;
begin
if dep=3 then exit;
for i:=1 to 3 do
if (l[dep]=0) then
begin
ans:=ans+f[dep];
l[dep]:=1;
dfs(dep+1);
end;
end;
begin
dfs(1);
writeln(ans);
end.

## 4.spfa

type
arr=record
x,y,w,next:longint;
end;
var
edge:array[0..10000] of arr;
ls,t,state:array[0..100000] of int64;
exits:array[0..10000] of boolean;
i,j,k,n,m,q,p,o,s,l,a,b:longint;
procedure spfa;
var
begin
state[1]:=0;
exits[1]:=true;
t[1]:=1;
repeat
while i<>0 do
begin
with edge[i] do
begin
if state[x]+w<state[y] then
begin
state[y]:=state[x]+w;
if exits[y]=false then
begin
inc(tail);
t[tail]:=y;
exits[y]:=true;
end;
end;
i:=next;
end;
end;
end;
begin

fillchar(state,sizeof(state),63);
n:=2; m:=3;
edge[1].x:=1; edge[1].y:=2; edge[1].w:=a; edge[1].next:=0;
edge[2].x:=2; edge[2].y:=3; edge[2].w:=b; edge[1].next:=0;
ls[1]:=1; ls[2]:=2;
spfa;
writeln(state[3])
end.
1
0

个人资料
• 访问：93348次
• 积分：4574
• 等级：
• 排名：第7650名
• 原创：317篇
• 转载：1篇
• 译文：0篇
• 评论：67条