题目: |
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
|