code forces 1173 B. Nauuo and Chess

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 }

猜你喜欢

转载自www.cnblogs.com/blowhail/p/10991237.html