当前位置:网站首页>2022 Henan Mengxin League Game (5): University of Information Engineering K - Matrix Generation
2022 Henan Mengxin League Game (5): University of Information Engineering K - Matrix Generation
2022-08-10 06:32:00 【WA_Automata】
K - 矩阵生成
P2615 [NOIP2015 提高组] 神奇的幻方
First open a group of loop input.Then assign the number in the middle of the first row as 1,定义一个x,y表示当前位置,把x赋值为1,y赋值为(n+1)/2.
Next, open a set of loops,根据x,y的值(即K-1的坐标)Determine how to fill in the numbers,After filling in the numbers will bex,yThe value of is assigned the current coordinate.
Finally when the number of loops is reachedn*nend and output
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N][N];
int main()
{
int n;cin>>n;
int x=1,y=(n+1)/2;
a[x][y]=1;
for(int i=2; i<=n*n; i++)
{
if(x==1&&y!=n)
{
x=n;
y++;
}
else if(x!=1&&y==n)
{
x--;
y=1;
}
else if(x==1&&y==n) x++;
else if(!a[x-1][y+1])
{
x--;
y++;
}
else x++;
a[x][y]=i;
}
for(int i=1; i<=n; i++)
{
cout << a[i][1];
for (int j=2; j<=n; j++) cout << ' ' << a[i][j];
cout << endl;
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
OpenGL学习笔记(LearnOpenGL)-第二部分 绘制三角形
Qt列表下方增加弹出加载数据提示效果
动态规划——从0-1背包问题到leetcode正则匹配
Talking about the realization idea of "frame" of "frame synchronization online game"
关于MongoDb查询Decimal128转BigDecimal问题
QScroller的QScrollerProperties参数研究
qemu and host share disk
pthread编程重要知识点
求职
Qt滚动条(QScrollBar)圆角样式问题跟踪
order by注入与limit注入,以及宽字节注入
2022河南萌新联赛第(五)场:信息工程大学 K - 矩阵生成
UnityShader入门精要-纹理动画、顶点动画
结构体初阶
机器学习_LGB调参汇总(开箱即食)
求问各位大佬,FLink SQL读取source的时候去指定水位线的时间字段,如果指定的这个字段中格
【强化学习】《Easy RL》- Q-learning - CliffWalking(悬崖行走)代码解读
Kernel Image File Format
Unity object pool implementation
Qt程序字体初始化引起的白屏问题









