当前位置: 首页 > news >正文

C++ | Leetcode C++题解之第519题随机翻转矩阵

题目:

题解:

class Solution {
public:Solution(int m, int n) {this->m = m;this->n = n;this->total = m * n;srand(time(nullptr));}vector<int> flip() {int x = rand() % total;vector<int> ans;total--;   // 查找位置 x 对应的映射if (map.count(x)) {ans = {map[x] / n, map[x] % n};} else {ans = {x / n, x % n};}// 将位置 x 对应的映射设置为位置 total 对应的映射if (map.count(total)) {map[x] = map[total];} else {map[x] = total;}return ans;}void reset() {total = m * n;map.clear();}
private:int m;int n;int total;unordered_map<int, int> map;
};
http://www.lryc.cn/news/475948.html

相关文章:

  • vrrp和mstp区别
  • 前端页面整屏滚动fullpage.js简单使用
  • JQuery基本介绍和使用方法
  • 【案例】旗帜飘动
  • 大模型思维链推理的综述:进展、前沿和未来
  • 项目一:使用 Spring + SpringMVC + Mybatis + lombok 实现网络五子棋
  • openEuler 系统中 Samba 文件共享服务器管理(windows、linux文件共享操作方法)
  • 使用 Elasticsearch 进行语义搜索
  • 软考:中间件
  • 银行家算法(Banker’s Algorithm)
  • 用魔数严谨的判别文件类型:杜绝上传风险
  • 【MacOS实操】如何基于SSH连接远程linux服务器
  • EXPLAIN 针对性优化 SQL 查询
  • MR30分布式IO:石化行业的智能化革新
  • linux图形化X窗口
  • 练习LabVIEW第三十五题
  • Decision Tree Regressor (决策树) --- 论文实战
  • 三层交换技术,eNSP实验讲解
  • 单链表OJ题(3):合并两个有序链表、链表分割、链表的回文结构
  • 研究了100个小绿书十万加之后,我们发现2024小绿书独家秘籍就是:在于“先抄后超,持续出摊,量大管饱”!
  • Java 中 HashMap集合使用
  • #渗透测试#SRC漏洞挖掘# 信息收集-Shodan进阶之Mongodb未授权访问
  • 平台化运营公司如何在创业市场招商
  • 飞书API-获取tenant_access_token
  • (新)docker desktop镜像迁移
  • 单向函数、单向陷门函数、困难问题
  • MYSQL 小猫钓鱼 - 猫王争霸之〈主从设计〉
  • arcgis坐标系问题
  • ubuntu 24.04中安装 Easyconnect,并解决版本与服务器不匹配问题
  • 【软考】RUP相关考点总结