当前位置:网站首页>ACM. Hj35 serpentine matrix ●
ACM. Hj35 serpentine matrix ●
2022-06-21 21:33:00 【chenyfan_】
HJ35 Snake matrix ●
describe
The snake matrix is made up of 1 The first natural numbers are arranged in sequence Triangle on matrix .
for example , When the input 5 when , The triangle that should be output is :
1 3 6 10 15
2 5 9 14
4 8 13
7 12
11
Input description :
Enter a positive integer N(N No more than 100)
Output description :
Output one N Snake matrix of row .
Example
Input :
4
Output :
1 3 6 10
2 5 9
4 8
7
Answer key
1. mathematics
According to the laws of Mathematics , Line by line calculation and output .

#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
int matrix[n][n];
for(int i = 0; i < n; ++i){
int num = i+2;
matrix[i][0] = (i+1)*i/2 + 1; // First column
cout << matrix[i][0] << " ";
for(int j = 1; j < n-i; ++j){
// A line
matrix[i][j] = matrix[i][j-1] + num;
++num; // Addition number
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}
2. simulation
The method of generating simulated serpentine matrix .

#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
int matrix[n][n];
int num = 1;
for(int i = 1; i <= n; ++i){
// Serpentine matrix generation
int row = i - 1;
int col = 0;
for(int j = 1; j <= i; ++j){
matrix[row--][col++] = num++;
}
}
for(int i = 0; i < n; ++i){
// Output
for(int j = 0; j < n-i; ++j){
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}
边栏推荐
- [OWT] P2P signaling server running
- 腾讯全球数字生态大会-高速智能计算专场!
- 潮流媒體Hypebeast擬曲線上市:作價5.3億美元 擬第三季完成
- MySQL数据库---数据库基础
- Database management: Navicat premium 15
- N - string problem HDU - 3374 (max min notation template)
- 天齐锂业通过聆讯:单季净利33亿 蒋卫平夫妇身价超500亿
- How to solve the problem of automatically updating the click times of weaving dream article list
- What plug-ins are available for vscade?
- What is the C language callback function?
猜你喜欢

Caricature scientifique | Vous pouvez apprendre l'EEG en regardant les images. Voulez - vous essayer?

PowerPoint tutorial, how to organize slides into groups in PowerPoint?

Asynchronous method understanding (demo with code)

What is the C language callback function?

Write your own compiler: intermediate code generation for loop statements such as while, for, and do

2016 ICLR | Adversarial Autoencoders

哪些ipad的APP可以很好的阅读英文文献?

英文论文要怎么查重?

2022年最新河南建筑施工电工(建筑特种作业)模拟试题及答案

潮流媒体Hypebeast拟曲线上市:作价5.3亿美元 拟第三季完成
随机推荐
Product innovation - an innovative social app that returns to real life
What is the C language callback function?
NewOJ Week 6
matplotlib plt.subplots()详解
NewOJ Week 6
有哪些新手程序員不知道的小技巧?
What can one line of code do?
集群一---LVS負載均衡集群NAT模式及LVS負載均衡實戰部署
Trend media Hypebeast plans to be listed on the curve: with a price of USD 530million, it is planned to be completed in the third quarter
2022 National latest fire facility operator (intermediate fire facility operator) simulation question bank and answers
测评 | 在生活中,你是一位什么样的人呢?
MySQL数据库---数据库基础
[MySQL · water drop plan] the third part - basic concepts of SQL
ctfshow 105-127
Xmind8 latest cracking tutorial (useful for personal testing)
30 groups of outdoor travel vlog record LUTS color matching preset moody travel LUTS
N - String Problem HDU - 3374(最大最小表示法模板)
Caricature scientifique | Vous pouvez apprendre l'EEG en regardant les images. Voulez - vous essayer?
浅谈代码语言的魅力
Write your own compiler: intermediate code generation for loop statements such as while, for, and do