code forces 1173 B. Nauuo and Chess

本文解析了CodeForces竞赛中B题“NauuoandChess”的解决方案,介绍了一个m×m棋盘放置n个棋子的问题,确保任意两棋子间的曼哈顿距离不小于它们的编号差。通过观察斜对角线规律,提出了一种高效的棋子放置算法。

本文链接:https://www.cnblogs.com/blowhail/p/10991237.html

B. Nauuo and Chess  原题链接:http://codeforces.com/contest/1173/problem/B

题目大意: 在一个m x m的棋盘中放n个棋子,满足 |rirj|cicj≥ |ij|   |ri−rj| + |ci−cj| ≥ |i−j|   (r为行,c为列)

大致思路:找规律之后可以发现,斜对角线上可以放的最大棋子数满足1 3 5 7 ....

如图

 

因此,我们可以这样放棋子:

代码如下:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <string>
 5 #include <cstring>
 6 #include <cmath>
 7 #define ll long long
 8 using namespace std;
 9 
10 int main ()
11 {
12     int i,t,m,n,u,sum,maxs,mins,x,y,z;
13     scanf("%d",&n);
14     m=n/2+1; //根据规律,直接算出棋盘大小
15     printf("%d\n",m);
16     for(i=1;i<=m;++i)
17         printf("%d %d\n",1,i);
18     for(i=2;i<=n-m+1;++i)
19         printf("%d %d\n",i,m);
20 
21     return 0;
22 }

 

转载于:https://www.cnblogs.com/blowhail/p/10991237.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值