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 ...
随机推荐
- Vue.js devtool插件安装后无法使用的解决办法
初次使用Vue.js devtool插件的新人在安装了Vue.js devtool插件后,都会经常有一个疑问.我在chrome浏览器里面已经成功安装好Vue.js devtool插件,怎么点击后提示v ...
- 动态IP下群晖搭建DDNS服务
转载地址:https://www.zimrilink.com/share/dsm_aliddns_server.html 通过阿里云API(php)搭建出DDNS动态域名解析服务器;不同的是本文的方法 ...
- install docker
摘要: 我的环境是:CentOS-7-x86_64-Minimal-1511.iso , 也可参考docker官网文档,来安装, url : https://docs.docker.com/engin ...
- Redo Gap 处理与优化
理论背景 当redo data 传送发生中断时就会产生redo gap.当redo 传送恢复正常以后,redo transport service 会自动检测redo gap并发送缺失的redo 到d ...
- 向nexus远程仓库里面添加JAR
向nexus远程仓库里面添加JAR 远程仓库:http://10.1.252.21:8081/nexus/index.html admin/admin123 方法一:手动 在左侧选择:Reposito ...
- ScrollView cannot scroll in Slidinguppanellayout 解决办法
xml源码如下 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:an ...
- DL杂谈
好久不写了,几点这次项目经验吧,本次训练位多任务训练,主要目的训练人脸角度,具体公司项目不细谈. 讲一下主要碰到的坑: 1 最主要问题,网络结构不对称,导致主任务与辅助任务之间的梯度关系不平衡从而导致 ...
- file -i haha.csv
user@user-desk ~/Downloads/largetrd$ file -i LT_Largetrd.csvLT_Largetrd.csv: text/plain; charset=utf ...
- day1 java基础回顾-内省
为什么要学内省? 开发框架时,经常需要使用java对象的属性来封装程序的数据,每次都使用反射技术完成此类操作过于麻烦,所以sun公司开发了一套API,专门用于操作java对象的属性. 内省是用于操作j ...
- GridView 72般绝技
GridView无代码分页排序 GridView选中,编辑,取消,删除 GridView正反双向排序 GridView和下拉菜单DropDownList结合 GridView和CheckBox结合 鼠 ...