B. Nauuo and Chess (简单构造)

Nauuo is a girl who loves playing chess.

One day she invented a game by herself which needs 𝑛n chess pieces to play on a 𝑚×𝑚m×m chessboard. The rows and columns are numbered from 11 to 𝑚m. We denote a cell on the intersection of the 𝑟r-th row and 𝑐c-th column as (𝑟,𝑐)(r,c).

The game's goal is to place 𝑛n chess pieces numbered from 11 to 𝑛n on the chessboard, the 𝑖i-th piece lies on (𝑟𝑖,𝑐𝑖)(ri,ci), while the following rule is satisfied: for all pairs of pieces 𝑖i and 𝑗j, |𝑟𝑖𝑟𝑗|+|𝑐𝑖𝑐𝑗||𝑖𝑗||ri−rj|+|ci−cj|≥|i−j|. Here |𝑥||x| means the absolute value of 𝑥x.

However, Nauuo discovered that sometimes she couldn't find a solution because the chessboard was too small.

She wants to find the smallest chessboard on which she can put 𝑛n pieces according to the rules.

She also wonders how to place the pieces on such a chessboard. Can you help her?

Input

The only line contains a single integer 𝑛n (1𝑛10001≤n≤1000) — the number of chess pieces for the game.

Output

The first line contains a single integer — the minimum value of 𝑚m, where 𝑚m is the length of sides of the suitable chessboard.

The 𝑖i-th of the next 𝑛n lines contains two integers 𝑟𝑖ri and 𝑐𝑖ci (1𝑟𝑖,𝑐𝑖𝑚1≤ri,ci≤m) — the coordinates of the 𝑖i-th chess piece.

If there are multiple answers, print any.

Examples
input
Copy
2
output
Copy
2
1 1
1 2
input
Copy
4
output
Copy
3
1 1
1 3
3 1
3 3
Note

In the first example, you can't place the two pieces on a 1×11×1 chessboard without breaking the rule. But you can place two pieces on a 2×22×2 chessboard like this:

In the second example, you can't place four pieces on a 2×22×2 chessboard without breaking the rule. For example, if you place the pieces like this:

then |𝑟1𝑟3|+|𝑐1𝑐3|=|12|+|11|=1|r1−r3|+|c1−c3|=|1−2|+|1−1|=1, |13|=2|1−3|=2, 1<21<2; and |𝑟1𝑟4|+|𝑐1𝑐4|=|12|+|12|=2|r1−r4|+|c1−c4|=|1−2|+|1−2|=2, |14|=3|1−4|=3, 2<32<3. It doesn't satisfy the rule.

However, on a 3×33×3 chessboard, you can place four pieces like this:

 

思路:
其实不难想到如果想要放的棋子最多,我们肯定是把最大的放在右下角,最小的放左上角。   那么可以得到   2 * (n - 1) >= m-1     (n是棋盘行数,m是棋子数)

也就是  2 *n - 1 >= m

有了这个关系,我们就沿着边拜放就可以了

 1 #include <iostream>
 2 #include <time.h>
 3 #include <algorithm>
 4 #include <stdio.h>
 5 
 6 typedef long long LL;
 7 
 8 using namespace std;
 9 
10 int main(){
11     int m;
12     scanf("%d",&m);
13     int n = m/2+1;
14     printf("%d\n",n);
15     for (int i=1;i<=n && i<=m;i++){
16         printf("%d %d\n",1,i);
17     }
18     int cnt = m-n;
19     for (int i=2;cnt;cnt--,i++){
20         printf("%d %d\n",i,n);
21     }
22     return 0;
23 
24 }

 

全部评论

相关推荐

来,说点可能被同行“骂”的大实话。🙊当初接数字马力Offer时,朋友都说:“蚂蚁的“内包”公司?你想清楚啊!”但入职快一年后的今天,我反而对他有了不一样的看法!🔹&nbsp;是偏见?还是信息差!之前没入职之前外面都在说什么岗位低人一等这类。实际上:这种情况不可至否,不能保证每个团队都是其乐融融。但我在的部门以及我了解的周边同事都还是十分好相处的~和蚂蚁师兄师姐之间也经常开一些小玩笑。总之:身份是蚂蚁公司给的,地位是自己挣的(一个傲娇女孩的自述)。🔹&nbsp;待遇?玩的就是真实!试用期工资全额发!六点下班跑得快(早9晚6或者早10晚7,动态打卡),公积金顶格交。别听那些画饼的,到手的钱和下班的时间才是真的(都是牛马何必难为牛马)。🔹&nbsp;能不能学到技术?来了就“后悔”!我们拥有权限直通蚂蚁知识库,技术栈多到学不完。说“学不到东西”的人,来了可能后悔——后悔来晚了(哈哈哈哈,可以不学但是不能没有)!💥&nbsp;内推地址:https://app.mokahr.com/su/ueoyhg❗我的内推码:NTA6Nvs走我的内推,可以直达业务部门,面试流程更快速,进度可查!今天新放HC,之前挂过也能再战!秋招已经正式开始啦~机会就摆在这,敢不敢来试一试呢?(和我一样,做个勇敢的女孩)
注意格局:去年超发意向是忘了
帮你内推|数字马力 校招
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务