Codeforces Round #564 (Div. 2) B. Nauuo and Chess
链接: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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #564 (Div. 1)
Codeforces Round #564 (Div. 1) A Nauuo and Cards 首先如果牌库中最后的牌是\(1,2,\cdots, k\),那么就模拟一下能不能每次打出第\(k+i\ ...
- Codeforces Round #564 (Div. 2)B
B. Nauuo and Chess 题目链接:http://codeforces.com/contest/1173/problem/B 题目 Nauuo is a girl who loves pl ...
- Codeforces Round #564 (Div. 2)
传送门 参考资料 [1]: the Chinese Editoria A. Nauuo and Votes •题意 x个人投赞同票,y人投反对票,z人不确定: 这 z 个人由你来决定是投赞同票还是反对 ...
- Codeforces Round #564 (Div. 2)A
A. Nauuo and Votes 题目链接:http://codeforces.com/contest/1173/problem/A 题目 Nauuo is a girl who loves wr ...
- 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 ...
- 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 ...
随机推荐
- BZOJ 1638 [Usaco2007 Mar]Cow Traffic 奶牛交通:记忆化搜索【图中边的经过次数】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1638 题意: 给你一个有向图,n个点,m条有向边. 对于所有从入度为0的点到n的路径,找出 ...
- sublime 3好用快捷键
sublime 3好用快捷键 自己常用 删除行 [ { "keys": ["ctrl+shift+d"], "command": " ...
- 网站桌面端和手机端不同url的设置
你的网站在搜索引擎中表现怎样很大程度上依赖于你的你的网站对于不同设备上的设计. 下面介绍了怎样基于URL构造来优化你的网站对于搜索引擎的支持. 决定你网页的URL构造 Determine the UR ...
- 语义化npm版本号
参考资料: 语义化版本2.0.0 the semantic versioner for npm 在package的devDependencies和dependencies2个字段中有指定依赖包版本,这 ...
- base64编码方式
一.编码的两大方式: 在python3.x中,字符串编码分为unicode和bytes两大类编码方式. 直接书写s='中国人',这种方式定义的编码方式为unicode,是通用的方式. 另一种是byte ...
- ef 多个模块,通过程序集映射entity,指定对应的repository
在Entity Framework repository下加两个方法: public virtual T GetByEntityName(object id, string EntityTypeNam ...
- Django 发送email配置详解及各种错误类型
跟随Django Book的内容发送邮件不成功,总结一下需要配置好settings.py文件,还要注意一些细节. 1.在settings文件最后添加以下内容,缺一不可! EMAIL_HOST= 'sm ...
- 有趣的Javascript:只需一个JS让万恶的IE5、IE6、IE7、IE8全都支持H5原生Canvas绘图(有演示demo)
该demo支持IE5以上任意内核的浏览器 查看演示demo:支持IE5以上版本的浏览器Canvas绘图demo 补充:chats.js和echarts等图表库也可以使用本方法兼容IE6以上浏览器 1. ...
- 洛谷 2585 [ZJOI2006]三色二叉树——树形dp
题目:https://www.luogu.org/problemnew/show/P2585 可以把不是绿色的记成一种.仔细一想不会有冲突.如果自己是绿色,孩子的不同颜色不会冲突:如果自己不是绿色,自 ...
- .Net 学习资源整理
01.Visual Studio 隐藏的财富 --- C# 语言规范 安装完Visual Studio之后,我们好像忽略了,微软给我们准备的<C# 语言规范>. 路径参考下图: 02.MS ...