博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #564 (Div. 2) B. Nauuo and Chess
阅读量:6957 次
发布时间:2019-06-27

本文共 1699 字,大约阅读时间需要 5 分钟。

链接:

题意:

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, |rirj|+|cicj||ij||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 
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;}

  

转载于:https://www.cnblogs.com/YDDDD/p/10990876.html

你可能感兴趣的文章
MIPI RFFE
查看>>
redis设置自动启动
查看>>
JS 中substr 和 substring
查看>>
Linux CentOS6.5本地yum源安装测试
查看>>
第四十天
查看>>
linux下重要文件夹的解析
查看>>
连接查询
查看>>
BZOJ1823[JSOI2010]满汉全席——2-SAT+tarjan缩点
查看>>
【UIKit】UITableView 6 编辑模式
查看>>
uva 10994 - Simple Addition
查看>>
团队作业4--第一次项目冲刺(Alpha版本)6
查看>>
python 主要模块和方法
查看>>
XPath手册 [源于ZVON]
查看>>
26:IPMaskCheck识别有效的ip地址和掩码并分类统计
查看>>
[Android]Thread线程入门4--多线程
查看>>
[20190423]那个更快的疑问3.txt
查看>>
[20170705]理解linux su命令.txt
查看>>
iOS - ImageCache 网络图片缓存
查看>>
如何调整eclipse中代码字体大小
查看>>
ubuntu16.04下python2、python3环境选择与python升级(pip版本切换)
查看>>