链接: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. 深入理解JVM - 线程安全与锁优化 - 第十三章

    线程安全 当多个线程访问一个对象时,如果不用考虑这些线程在运行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方法进行任何其他的协调操作,调用这个对象的行为都可以获得正确的结果,那么这个对 ...

  2. C/C++的四大内存分区和常量的存储位置

    原文:https://blog.csdn.net/k346k346/article/details/45592329 正确的理解C/C++程序的内存分区,是合格程序猿的基本要求. 网络上流形两大版本内 ...

  3. jQuery精华

    第一章:入门 选择元素: $() css() $("li").css():可以省略原生的循环操作 $ == jQuery jQuery方法函数化: click() html() J ...

  4. win8、win10下卸载程序报错误2502、2503的解决办法

    首先打开任务管理器,可以通过右键点击桌面上的任务栏打开任务管理器,也可以通过同时按下键盘上的Ctrl+Alt+Delete键打开任务管理器. 打开任务管理器后,切换到“详细信息”选项卡,找到explo ...

  5. [转载]IOCP模型的总结

    原文:IOCP模型的总结 IOCP(I/O Completion Port,I/O完成端口)是性能最好的一种I/O模型.它是应用程序使用线程池处理异步I/O请求的一种机制.在处理多个并发的异步I/O请 ...

  6. Merge into使用详解( 同时执行inserts和updates操作 )

    Merge是一个非常有用的功能,类似于MySQL里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...

  7. 优化EF的性能

    Entity Framework的性能优化: 1.使用MergeOption.NoTracking  (发现添加这个代码后, 导致"The object cannot be deleted ...

  8. AI-Info-Micron-Insight:Micron 美光的技术帮助 CERN 解开宇宙奥秘

    ylbtech-AI-Info-Micron-Insight:Micron 美光的技术帮助 CERN 解开宇宙奥秘 1.返回顶部 1. Micron 美光的技术帮助 CERN 解开宇宙奥秘 大约 14 ...

  9. Spring Web MVC 的HandlerMapping的使用之-------SimpleUrlHandlerMapping

    转自:https://www.2cto.com/kf/201401/271141.html Spring MVC教程 映射处理器Handler Mapping 一.简析映射处理器 在spring mv ...

  10. Hibernate错误:javax/persistence/EntityListeners

    1. 原文地址:http://heavengate.blog.163.com/blog/static/20238105320127291018026/ 错误信息: hibernate:javax/pe ...