当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Unity object pool implementation
数据库学习之表的约束
个人实现的可任意折叠QToolBox——AdvancedToolBox
761. 特殊的二进制序列
强化学习_05_DataWhale近端策略优化
UnityShader入门精要-基础纹理
OpenGL学习笔记(LearnOpenGL)-第六部分 变换
Unity plug-in DOTween User Guide 2 (Brief explanation of Bezier curves)
CuteOneP 一款php的OneDrive多网盘挂载程序 带会员 同步等功能
进制的前缀表示和后缀表示
强化学习_07_DataWhale深度Q网络进阶技巧
如何在AdsPower中设置YiLu代理?
强化学习_11_Datawhale模仿学习
Unity扩展编辑器EditorWindow 小玩意(一)
OpenGL学习笔记(LearnOpenGL)第一部分-环境配置与基础知识
Quickly grasp game resources in one hour and remote hot update
全网可达,交换机和路由器的配置,vlan
什么是代理ip?市面上好用的代理软件有哪些
机器学习_LGB调参汇总(开箱即食)
Share a professional TA's "Shader Reference"