Tất cả thử thách
Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Two Nonattacking Knights

Count safe placements of two knights for each square board size.

For each board size k from 1 through n, count unordered pairs of distinct squares on a k by k board where two knights cannot attack each other. A knight moves two squares in one axis and one in the other.

. x . x .
x . . . x
. . K . .
x . . . x
. x . x .

K marks a knight and x its possible destinations, when those squares lie on the board. Swapping the two knights does not create another placement.

Implement two_knights(n).

Input

n: The largest board size to consider.

Output

Return n counts in order, for board sizes 1 through n.

Ràng buộc

1 ≤ n ≤ 10,000. Counts fit signed 64-bit integers.

Ví dụ

Ví dụ 1
Đầu vào:
n = 3

Kết quả mong đợi:
expected = [0, 6, 28]
Đầu vào:
long long n = 3;

Kết quả mong đợi:
std::vector<long long> expected = {0, 6, 28};
Đầu vào:
long n = 3;

Kết quả mong đợi:
long[] expected = new long[] {0, 6, 28};

Giải thích

A 1 × 1 board cannot hold two knights. A 2 × 2 board has six pairs and no attacks. A 3 × 3 board has 36 pairs, of which eight attack, leaving 28.

Ví dụ 2
Đầu vào:
n = 1

Kết quả mong đợi:
expected = [0]
Đầu vào:
long long n = 1;

Kết quả mong đợi:
std::vector<long long> expected = {0};
Đầu vào:
long n = 1;

Kết quả mong đợi:
long[] expected = new long[] {0};

Giải thích

Two distinct squares are required, but the board has only one.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.