当前位置:网站首页>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;
}
边栏推荐
- Simplest character device driver
- Talking about 3 common shadow rendering techniques in games (2): shadow cone
- ArgumentException: GetComponent requires that the requested component ‘GameObject‘ derives from Mono
- npm搭建私服,上传下载包
- How is C# hot update better than Lua?
- MySQL 免安装版/解压版的安装与配置(Win & Unix & Linux)
- Unity资源热更新--资源管理、Addressable
- 强化学习_05_DataWhale近端策略优化
- 2022河南萌新联赛第(五)场:信息工程大学 K - 矩阵生成
- 新手使用 go channel 需要注意的问题
猜你喜欢
随机推荐
ArgumentException: GetComponent requires that the requested component ‘GameObject‘ derives from Mono
Unity的GetComponentsInChildren1、2、3
1413. 逐步求和得到正数的最小值
761. 特殊的二进制序列
OpenGL学习笔记(LearnOpenGL)-第五部分 纹理
Make a boot floppy and boot with bochs emulator
OpenGL学习笔记(LearnOpenGL)-第二部分 绘制三角形
Kernel performance analysis summary
QScroller的QScrollerProperties参数研究
elf文件与链接脚本
Talking about 3 Common Shadow Rendering Techniques in Games (3): Shadow Mapping
强化学习_08_Datawhale针对连续动作的深度Q网络
Qt使用私有接口绘制窗口阴影
netlink IPC
OpenGL学习笔记(LearnOpenGL)第一部分-环境配置与基础知识
强化学习_03_表格方法实践(CartPole-v0 And MontoCarlo)
Myunity框架笔记
Kernel performance analysis summary
3.事务篇【mysql高级】
动态代理-cglib