当前位置:网站首页>Acwing刷题第一节
Acwing刷题第一节
2022-07-30 05:46:00 【一只积极向上的小咸鱼】
756

题目分析 :
要点如下:
1. 矩阵遍历:确定遍历方向
2. 确定遍历边界
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
int n,m;
int res[N][N];
int main()
{
cin>>n>>m;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
for(int x = 0,y = 0 ,k = 1,d = 0;k<=n*m;k++)
{
res[x][y] = k;
int a = x+dx[d],b = y + dy[d];
if(a<0 || a>=n ||b<0||b>=m||res[a][b])
{
d = (d+1)%4;
a = x + dx[d], b = y+ dy[d];
}
x = a,y = b;
}
for(int i = 0;i<n;i++) {
for (int j = 0; j < m; j++) {
cout << res[i][j] << " ";
}
cout<<endl;
}
return 0;
}边栏推荐
猜你喜欢

服务器基础知识:包含基本概念,作用,服务器选择,服务器管理等(学习来自米拓建站)

边境的悍匪—机器学习实战:第十章 Keras人工神经网络简介

MindSpore 提 PR 全流程

Kunlun State Screen Production (Serialization 2)---Basic Chapter (setting and display, serial transmission)

QT serial 3: LORA test platform based on QT and STM32H750 (2)

influxDB运维记录

FPGA解析B码----连载2

边境的悍匪—机器学习实战:第三章 分类

【江科大自化协stm32F103c8t6】笔记之【入门32单片机及利用TIM输出比较配置PWM】

华秋电子成为开放原子开源基金会openDACS捐赠人,共建 openDACS开源生态
随机推荐
Cannnot download sources不能下载源码百分百超详细解决方案
QT serialization 1: readyRead() function, the solution to incomplete data subcontracting
你不知道的JS思考题
Written before the official account - QT, ARM, DSP, microcontroller, power electronics and transmission!
DeepLearing4j's deep learning Yolo Tiny realizes target detection
边境的悍匪—机器学习实战:第三章 分类
点云统计滤波理解
边境的悍匪—机器学习实战:第九章 无监督学习任务
边境的悍匪—机器学习实战:第十章 Keras人工神经网络简介
边境的悍匪—机器学习实战:第十五章 使用CNN和RNN处理序列
边境的悍匪—Kaggle—泰坦尼克号生还预测详细教程
Simulation of Future Air Pollution Changes Based on Global Model Comparison Program CMIP6 and Regional Climate-Chemistry Coupling Model WRF-Chem
jvm之逃逸分析
Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
边境的悍匪—机器学习实战:第十二章 使用TensorFlow自定义模型和训练
边境的悍匪—机器学习实战:第四章 训练模型
华秋电子成为开放原子开源基金会openDACS捐赠人,共建 openDACS开源生态
Real-time waveform display of CAN communication data based on QT (serial eight) ==== "Sub function or new class calls ui control"
ipconfig Command Guide
边境的悍匪—机器学习实战:第七章 集成学习和随机森林