牛客网 牛客小白月赛2 A.数字方阵-反魔方阵,梁邱构造法

天坑未补。。。

水一波博客,再不写博客就咸成鱼干了,只写题不写题解,过一段时间就忘了自己学过什么了。

最近重点就是把开学以来写的题补出来,没学的就滚去学会啊(= =),填一下坑。。。

从这篇博客开始,填最近的坑

先贴这些题的题解,剩下的3道题过一段时间补出来再贴。

开始表演。

 

A.数字方阵

链接:https://www.nowcoder.com/acm/contest/86/A

这个题是反魔方阵,正常的魔方阵是相同,这个是不相同,有一个神奇的东西,先来个传送门,biubiubiu

梁邱构造法(百度文库不让我粘贴,那我就截图,hhhhhh)

 

就这个神奇的构造法就可以,这道题就是水题了。
 
代码:
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<stack>
10 using namespace std;
11 typedef long long ll;
12 const int maxn=1e5+10;
13 const double eps=1e-7;
14 int main(){
15     int n;
16     cin>>n;
17     int cnt=1,ret=n*n-n+1;
18     for(int i=1;i<=n;i++){
19         for(int j=1;j<=n;j++){
20             if(j==n)cout<<ret++<<endl;
21             else cout<<cnt++<<" ";
22         }
23     }
24 }

 

 

 

 

posted @ 2018-04-23 22:23  ZERO-  阅读(357)  评论(0编辑  收藏  举报