当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

阿里云防火墙配置,多种设置方式(iptables和fireward)

使用Rancher搭建Kubernetes集群

The collapsing "2.3 * 10 = 22" produced by multiplying float and int

JVM之TLAB

Flutter 基础组件之 Container

Perfect binary tree, complete binary tree, perfect binary tree

Nacos environmental isolation

A 3D Dual Path U-Net of Cancer Segmentation Based on MRI

Constructing SQL statements by sprintf() function in C language

Using rancher to build kubernetes cluster
随机推荐
FreeRTOS (IX) - queue
51nod1277 maximum value in string [KMP]
Codeforces Round #641 Div2
Reverse thinking - short story
Database common interview questions (with answers)
Wandering --- 最后的编程挑战
Leetcode MySQL database topic 180
Flutter 基础组件之 Image
JVM之TLAB
1099 Build A Binary Search Tree (30 分)
2019.10.27训练总结
Listview of the basic component of the shutter
SeaweedFS安全配置(Security Configuration)
leetcode MYSQL数据库题目177
URAL1517 Freedom of Choice 【后缀数组:最长公共连续子串】
manacher
Setinterval, setTimeout and requestanimationframe
Related problems of pointer array, array pointer and parameter passing
Flutter 基础组件之 GridView
CodeForces - 1151B 思维