当前位置:网站首页>蛇形填数
蛇形填数
2022-06-29 09:23:00 【陌陌623】
试题C 蛇形填数
【问题描述】
如下图所示,小明用从1 开始的正整数“蛇形”填充无限大的矩阵。
容易看出矩阵第二行第二列中的数是5。请你计算矩阵中第20 行第20 列的数是多少?
【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一
个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
答案:761
#include <iostream>
using namespace std;
int a[100][100];
int main()
{
int t = 1;
// 当前的状态 0是下降 1是上升
int f = 1;
int i, j;
i = j = 1;
while (i < 50)
{
a[i][j] = t++;
// 如果到最上面了 并当前的状态是上升着的 说明需要下降了
if (i - 1 <= 0 && f)
{
j++;
f = 0;
continue;
}
else if (j - 1 <= 0 && !f) // 同上
{
i++;
f = 1;
continue;
}
// 控制上升和下降的两种行动
if (f)
i--, j++;
else
i++, j--;
}
cout << a[20][20];
return 0;
}
边栏推荐
- Flutter 基础组件之 ListView
- Leetcode MySQL database topic 177
- F5 BIG-IP iControl REST命令执行(CVE-2022-1388)
- 自定义控件之侧滑关闭 Activity 控件
- Reverse thinking - short story
- gcc与makefile
- Rikka with Cake(线段树+线段树)
- Application of decorator mode, packaging ServletRequest and adding addparameter method
- Codeforces Round #657 Div. 2
- How to traverse objects in the vector container
猜你喜欢

时变和非时变

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

基辅周边的凄美废墟——切尔诺贝利的安全前往指南!

Image of the basic component of the shutter

Force deduction 85 question maximum rectangle

Gmail:如何快速将邮件全部已读

完美二叉树、完全二叉树、完满二叉树

nacos注册中心集群

Alibaba cloud firewall configuration, multiple settings (iptables and firewall)

自定义控件之下载控件1(DownloadView1)
随机推荐
2019.11.17训练总结
A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
The Stones Game【取石子博弈 & 思维】
Sixteen system counter and flow lamp
leetcode MYSQL数据库题目180
Alternative implementation of Scrollview pull-down header amplification
HDU 4578 Transformation(线段树+有技巧的懒标记下放)
共用体Union
GSOAP example - calc
JVM四种调用方法的指令
RecyclerView 通用适配器封装
Container of the basic component of the flutter
gcc与makefile
leetcode MYSQL数据库题目176
Flutter 基础组件之 GridView
Leetcode MySQL database topic 177
MySQL modify auto increment initial value
Pointer functions and function pointers
详细分析PBot挖矿病毒家族行为和所利用漏洞原理,提供蓝军详细防护建议
Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages