当前位置:网站首页>LeetCode Daily Question (858. Mirror Reflection)
LeetCode Daily Question (858. Mirror Reflection)
2022-08-04 12:13:00 【wangjun861205】
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.
The square room has walls of length p and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor.
Given the two integers p and q, return the number of the receptor that the ray meets first.
The test cases are guaranteed so that the ray will meet a receptor eventually.
Example 1:

Input: p = 2, q = 1
Output: 2
Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.
Example 2:
Input: p = 3, q = 1
Output: 1
Constraints:
- 1 <= q <= p <= 1000
Imagine the room as an elevator, all the heights of m * p (m is an integer greater than 0) of the elevator are hung with sensors on the left and right sides, 2 and 1 on the odd floor, 2 and 0 on the even floor, and then thisThe problem becomes the problem of finding the least common multiple
impl Solution {pub fn mirror_reflection(p: i32,span> q: i32) -> i32 {let mut m = 1;let mut is_up = true;loop {if p * m % q == 0 {if p * m / q % 2 == 0span> {return 2;}if is_up {return 1;}return 0;}m += 1;is_up = !is_up;}}}边栏推荐
- POJ2367Genealogical tree题解
- The use of DDR3 (Naive) in Xilinx VIVADO (1) to create an IP core
- A Survey of Multi-Label Classification under Supervised and Semi-Supervised Learning
- yolo系列的Neck模块
- 六石编程学:编程中的直线思维与自然思维
- Transferring Rich Feature Hierarchies for Robust
- Flutter 使用 json_serializable 解析 JSON 支持泛型
- 全面认识MOS管,一篇文章就够了
- 云原生Devops 的实现方法
- 七夕还没选好礼物,快送这套美妆秘籍,保准没错~~
猜你喜欢

表的完整性约束;非外键约束

SchedulX V1.5.0发布,提供快速压测、对象存储等全新功能!

数据中台建设(九):数据中台资产运营机制

244 page PDF!"2022 China cloud computing ecological blue book published

Linux-Docker-Mysql安装

Shell loop statement (for, while, until)

A Survey of Multi-Label Classification under Supervised and Semi-Supervised Learning

免费翻译软件哪个好用

num_workers

考研概率论与数理统计(知识点梳理)
随机推荐
#夏日挑战赛#OpenHarmony 给你的输入法加点彩—星球崛起
项目管理前景
【RISC-V】Trap和Exception
能力更强,医疗单据识别+医疗知识库校验
划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板
表的完整性约束;非外键约束
节流函数(每隔一段时间就会执行一次)
MySQL必知必会(初级篇)
超美星空特效,你Get了吗?
TPC藏宝计划IDO自由协议复利模式开发功能分析
JS逆向字体反爬,某供应商平台反爬实践
*W3C* Standards Organization
244页pdf!《2022 中国云计算生态蓝皮书》发布
你值得拥有的登录注册页面(附赠源码)
Redis (1) installation and configuration
【VBox】解决复制VBox虚拟机后提示硬盘UUID 已经存在的问题
七夕还没选好礼物,快送这套美妆秘籍,保准没错~~
The sword refers to the Great Wall Cannon?Official spy photos of Changan's new pickup
MTBF是什么意思?交换机做MTBF有什么要求?MTTF、MTBF和MTTR的区别是什么?
Yolov5 测试和训练自己的数据集