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

时间:2023-03-09 16:13:47
牛客网 牛客小白月赛2 A.数字方阵-反魔方阵,梁邱构造法

天坑未补。。。

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

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

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

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

开始表演。

A.数字方阵

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

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

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

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

就这个神奇的构造法就可以,这道题就是水题了。
代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
const double eps=1e-;
int main(){
int n;
cin>>n;
int cnt=,ret=n*n-n+;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(j==n)cout<<ret++<<endl;
else cout<<cnt++<<" ";
}
}
}