当前位置:网站首页>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;
}
边栏推荐
- 关于报错vscode
- Analysis of domestic data exchange platforms
- CPU缓存一致性问题
- 边境的悍匪—机器学习实战:第十二章 使用TensorFlow自定义模型和训练
- QT serial 2: LORA test platform based on QT and STM32H750 (1)
- 虚拟机栈帧结构
- 点云统计滤波理解
- Based on R language geographic weighted regression, principal component analysis, discriminant analysis and other spatial heterogeneity data analysis
- 边境的悍匪—机器学习实战:第十三章 使用TensorFlow加载和预处理数据
- Written before the official account - QT, ARM, DSP, microcontroller, power electronics and transmission!
猜你喜欢
虚拟机栈帧结构
干货:线上下单应知应会,快来了解下
R language application in the field of ecological environment
查看 word版本号
Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition program running record
Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
昆仑通态屏幕制作(连载2)---基础篇(设定与显示,串口发送)
OpenLayers 初学者指南,源码测试可用
Diwen serial screen production (serialization 1) ===== preparation work
QT serial and CAN dynamic real-time display the log data
随机推荐
Antd 树拖拽一些细节,官网没有,摸坑篇
openssl1.1.1ARM双编译
QT连载4:基于QT和STM32H750的LORA试验平台(3)
写在公众号之前——QT,ARM,DSP,单片机,电力电子与传动!
Sklearn : train_test_split()函数的用法
主机和从机配置,建立ssh连接实现Rviz远程控制
BLDC电机应用持续火爆,“网红神器”筋膜枪前景几何?
Simulation of Future Air Pollution Changes Based on Global Model Comparison Program CMIP6 and Regional Climate-Chemistry Coupling Model WRF-Chem
Based on R language geographic weighted regression, principal component analysis, discriminant analysis and other spatial heterogeneity data analysis
边境的悍匪—机器学习实战:第十章 Keras人工神经网络简介
PCB 一分钟科普之你真的懂多层板吗?
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及TIM定时中断初始化参数配置】
"R Language + Remote Sensing" Comprehensive Evaluation Method of Water Environment
暂时存着阿里云
openssl 1.1.1 compile statement
思谋面试准备
【正点原子】IIC的学习与使用(未完...)
vs编译boost库脚本
Difference between logical shift right and arithmetic right shift
Generalized Focal Loss paper reading notes