当前位置:网站首页>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;
}边栏推荐
- Antd简单启动一个企业级项目
- 干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
- 联影医疗一面
- openssl1.1.1ARM dual compilation
- 迪文串口屏幕制作(连载一)=====准备工作
- QT serial 4: LORA test platform based on QT and STM32H750 (3)
- Kunlun state screen production (serial 3) - based article (button serial port to send)
- 自定义类加载器
- OpenLayers (ol包),Vite显示地图(附源码)
- JS的值和引用,复制和传递
猜你喜欢

Configure MMdetection environment and train

Flood Control Assessment Report Compilation Method and Flood Modelling under the New Guidelines (HEC-RAS)

QT连载4:基于QT和STM32H750的LORA试验平台(3)

【江科大自化协stm32F103c8t6】笔记之【入门32单片机及GPIO初始化参数配置】

边境的悍匪—机器学习实战:第一章 机器学习的基础知识

R - GIS: how to use R language implementation of GIS geospatial analysis and model prediction

Atmospheric particulate matter PMF source analysis

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

QT连载3:基于QT和STM32H750的LORA试验平台(2)
CPU的三种工作模式:实模式、保护模式、长模式
随机推荐
Massive remote sensing data processing and application of GEE cloud computing technology [basic, advanced]
Configure MMdetection environment and train
Simulation of Future Air Pollution Changes Based on Global Model Comparison Program CMIP6 and Regional Climate-Chemistry Coupling Model WRF-Chem
你不知道的JS思考题
主机和从机配置,建立ssh连接实现Rviz远程控制
QT每周技巧(1)~~~~~~~~~运行图标
干货:线上下单应知应会,快来了解下
闭包和作用域(你不知道的JS自用笔记)
Target detection, object classification and semantic segmentation of UAV remote sensing images based on PyTorch deep learning
QT串口动态实时显示大量数据波形曲线(五)========“最终完美解决版”
BLDC电机应用持续火爆,“网红神器”筋膜枪前景几何?
基于OpenCV的相机标定流程
Real-time waveform display of CAN communication data based on QT (serial eight) ==== "Sub function or new class calls ui control"
2021-09-19 集成学习TASK2
UAV ecological environment monitoring, image processing and GIS data analysis
CLUE Model Construction Method, Model Validation and Land Use Change Scenario Prediction
QT连载1:readyRead()函数,数据分包不完整解决办法
QT serial 3: LORA test platform based on QT and STM32H750 (2)
高效插入map数据
openssl1.1.1ARM dual compilation