当前位置:网站首页>Serpentine filling number
Serpentine filling number
2022-06-29 10:13:00 【Momo 623】
test questions C Snake fill in
【 Problem description 】
As shown in the figure below , Xiao Ming uses from 1 A positive integer at the beginning “ Serpentine ” Fill an infinite matrix .
It is easy to see that the number in the second row and second column of the matrix is 5. Please calculate the number... In the matrix 20 Xing di 20 What's the number of columns ?
【 Answer submission 】
This is a question to fill in the blanks , You just need to work out the results and submit them . The result of this question is one
It's an integer , Only fill in the whole number when submitting the answer , Fill in the extra content will not be able to score .
answer :761
#include <iostream>
using namespace std;
int a[100][100];
int main()
{
int t = 1;
// Current state 0 It's down 1 It's going up
int f = 1;
int i, j;
i = j = 1;
while (i < 50)
{
a[i][j] = t++;
// If you get to the top And the current state is on the rise That means it needs to be lowered
if (i - 1 <= 0 && f)
{
j++;
f = 0;
continue;
}
else if (j - 1 <= 0 && !f) // ditto
{
i++;
f = 1;
continue;
}
// Two actions to control ascent and descent
if (f)
i--, j++;
else
i++, j--;
}
cout << a[20][20];
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Summary of PHP memory horse technology research and killing methods
RecyclerView 通用适配器封装
山科 的C语言2018练习题(电信)
Wandering --- 最后的编程挑战
If I were in Beijing, where would it be better to open an account? In addition, is it safe to open an account online now?
51nod1277 maximum value in string [KMP]
Dsolve function of sympy
Codeforces Round #641 Div2
Minorgc, majorgc, fullgc
JNI.h说明
SymPy Tutorial(译)
2019icpc上海区域赛赛后总结
Flutter 基础组件之 Container
Sublime Text3 set to run your own makefile
信号作品:时变和时不变
2019-11-10训练总结
2019.10.27 training summary
【51nod 1215】数组的宽度
2019.10.16训练总结
Perfect binary tree, complete binary tree, perfect binary tree








