链接:https://codeforces.com/contest/1173/problem/B

题意:

Nauuo is a girl who loves playing chess.

One day she invented a game by herself which needs nn chess pieces to play on a m×mm×mchessboard. The rows and columns are numbered from 11 to mm. We denote a cell on the intersection of the rr-th row and cc-th column as (r,c)(r,c).

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

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 nn pieces according to the rules.

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

思路:

构造x*x的矩阵,左上角放1,右下角放n,

因为(n-x)=(n-x)

所以矩阵第一行填满1-x,最后一行从右到左填充n-(x+1)。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 1e3 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
int x, y; int A[MAXN][MAXN]; int main()
{
cin >> n;
if (n == 1)
{
cout << 1 << endl;
cout << 1 << ' ' << 1 << endl;
return 0;
}
for (int i = 2;i <= n;i++)
if ((i-1)*2 >= n-1)
{
x = y = i;
break;
}
for (int i = 1;i <= x;i++)
A[1][i] = i;
for (int i = x, v = n;i >= 1 && v > x;i--,v--)
A[x][i] = v; cout << x << endl;
for (int i = 1;i <= x;i++)
for (int j = 1;j <= y;j++)
if (A[i][j] <= n && A[i][j] >= 1)
cout << i << ' ' << j << endl; return 0;
}

  

Codeforces Round #564 (Div. 2) B. Nauuo and Chess的更多相关文章

  1. Codeforces Round #564 (Div. 2) C. Nauuo and Cards

    链接:https://codeforces.com/contest/1173/problem/C 题意: Nauuo is a girl who loves playing cards. One da ...

  2. Codeforces Round #564 (Div. 2) A. Nauuo and Votes

    链接:https://codeforces.com/contest/1173/problem/A 题意: Nauuo is a girl who loves writing comments. One ...

  3. Codeforces Round #564 (Div. 2) D. Nauuo and Circle(树形DP)

    D. Nauuo and Circle •参考资料 [1]:https://www.cnblogs.com/wyxdrqc/p/10990378.html •题意 给出你一个包含 n 个点的树,这 n ...

  4. Codeforces Round #564 (Div. 1)

    Codeforces Round #564 (Div. 1) A Nauuo and Cards 首先如果牌库中最后的牌是\(1,2,\cdots, k\),那么就模拟一下能不能每次打出第\(k+i\ ...

  5. Codeforces Round #564 (Div. 2)B

    B. Nauuo and Chess 题目链接:http://codeforces.com/contest/1173/problem/B 题目 Nauuo is a girl who loves pl ...

  6. Codeforces Round #564 (Div. 2)

    传送门 参考资料 [1]: the Chinese Editoria A. Nauuo and Votes •题意 x个人投赞同票,y人投反对票,z人不确定: 这 z 个人由你来决定是投赞同票还是反对 ...

  7. Codeforces Round #564 (Div. 2)A

    A. Nauuo and Votes 题目链接:http://codeforces.com/contest/1173/problem/A 题目 Nauuo is a girl who loves wr ...

  8. Codeforces Round #379 (Div. 2) D. Anton and Chess 水题

    D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...

  9. Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟

    题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmem ...

随机推荐

  1. SpringBoot_00_资源汇总贴

    一.精选 1.Spring Boot文档 二.参考资料 1.springboot-learning-example 2.Spring boot 那些事 3.Spring Boot干货系列 4.Spri ...

  2. c# json 排版

    public static string PraseToJson(string json) { try { JsonSerializer s = new JsonSerializer(); JsonR ...

  3. Quartz.Net初探

    想必大家在工作中经常会遇到这样类似的需求,在某个时间或者需要不间断的执行某个业务动作去满足任务需求.例如,我们写了一个job,定时去处理一些任务,在没有了解到Quartz.Net之前,我是这样做的,进 ...

  4. Visual Studio 2012 与此版本的 Windows 不兼容 解决

    警告: [Window Title] 程序兼容性助手[Main Instruction] 此程序存在已知的兼容性问题[Expanded Information] Visual Studio 2012 ...

  5. wingide 显示中文 及 配色方案

    http://lihuipeng.blog.51cto.com/3064864/923231 网上收集的方法: 显示中文: 任意文本编辑器打开:x:\Wing IDE\bin\gtk-bin\etc\ ...

  6. hdu3739 Anti LIS[最小割]

    长度为 n≤1000 的数列 ai,其中最长上升子序列的长度为 s.至少删去多少数使得最长上升子序列的长度小于 s. 其实这题和那个求有多少不重叠LIS是一样答案的. 先放个图. 图丑别说我. 原网络 ...

  7. 「USACO08DEC」「LuoguP2922」秘密消息Secret Message(AC自动机

    题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...

  8. 洛谷 P4106 / bzoj 3614 [ HEOI 2014 ] 逻辑翻译 —— 思路+递归

    题目:https://www.luogu.org/problemnew/show/P4106 https://www.lydsy.com/JudgeOnline/problem.php?id=3614 ...

  9. PCB上的导线 怎么开窗 去掉绿油 把铜皮裸露

    开窗是个专业术语,你可以简单的理解为"去掉绿油,把铜皮裸露". 导线开窗用途一: 例如这个板子中的蛇形天线,就是导线开窗后的效果. 导线开窗用途二: 把需要过大电流的导线开窗,就可 ...

  10. HDU - 6201 transaction transaction transaction(树形dp取两点)

    transaction transaction transaction Kelukin is a businessman. Every day, he travels around cities to ...