不是VIP会员,不能显示答案

题目解答

题目:
var
f: array[1..100, 1..100] of longint;
cnt: longint;
i, j, n, t, x, y, ans: longint;
begin
read(n);
x := 1;
y := 0;
for i := 1 to n do
begin
for j := 1 to n*2-i+1 do
begin
inc(y);
inc(cnt);
f[x, y] := cnt;
end;
for j := 1 to n*2-i do
begin
inc(x);
inc(cnt);
f[x, y] := cnt;
end;
for j := 1 to n*2-i do
begin
dec(y);
dec(cnt);
f[x, y] := cnt;
end;
for j := 1 to n*2-i-1 do
begin
dec(x);
dec(cnt);
f[x, y] := cnt;
end;
end;
read(t);
ans := 0;
for i := 1 to n*2 do
ans := ans + f[t, i];
writeln(ans);
end.
输入:3 2
输出:27
考点: 0
分析:
解答: 10
  1  2  3  4  5  6  7  8  9 10
  2  3  4  5  6  7  8  9 10 11
  3  4  5  6  7  8  9 10 11 12
  4  5  6  7  8  9 10 11 12 13
  5  6  7  8  9 10 11 12 13 14
  6  7  8  9 10 11 12 13 14 15
  7  8  9 10 11 12 13 14 15 16
  8  9 10 11 12 13 14 15 16 17
  9 10 11 12 13 14 15 16 17 18
10 11 12 13 14 15 16 17 18 19
评论:
老师: 0