题库练习 Half Queen Cover
← 上一题 下一题 →

A15028 | Half Queen Cover

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given a board with $n$ rows and $n$ columns, numbered from $1$ to $n$ . The intersection of the $a$ -th row and $b$ -th column is denoted by $(a, b)$ .

A half-queen attacks cells in the same row, same column, and on one diagonal. More formally, a half-queen on $(a, b)$ attacks the cell $(c, d)$ if $a=c$ or $b=d$ or $a-b=c-d$ .

![](/uploads/acgo/image/8fbef89ac88478f2_7f805b6a295a.jpeg)The blue cells are under attack. What is the minimum number of half-queens that can be placed on that board so as to ensure that each square is attacked by at least one half-queen?Construct an optimal solution.

输入格式

The first line contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the size of the board.

输出格式

In the first line print a single integer $k$ — the minimum number of half-queens.

In each of the next $k$ lines print two integers $a_i$ , $b_i$ ( $1 \le a_i, b_i \le n$ ) — the position of the $i$ -th half-queen.

If there are multiple solutions, print any.

输入输出样例

输入 #1
1
输出 #1
1
1 1
输入 #2
2
输出 #2
1
1 1
输入 #3
3
输出 #3
2
1 1
1 2
C++ 编辑器
输入
输出