当前位置:网站首页>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;}}}边栏推荐
猜你喜欢
随机推荐
揭秘交换机市场内幕,“准工业级”猫腻你中招了吗?
中电金信技术实践|分布式事务简说
【目标检测】------yolo:xml和txt文件相互转化
中电资讯 - 一路“标”升,喜迎Q3开门红
七夕还没选好礼物,快送这套美妆秘籍,保准没错~~
Hands-on Deep Learning_LeNet
Tapdata 开源项目基础教程:功能特性及实操演示
Redis(一)安装与配置
外键约束;外键约束
如何做好企业数字化转型?这10份靠谱案例收藏了(附下载)
POJ1094Sorting It All Out题解
2022上半年各银行理财子公司深耕差异化发展,净值型产品数量增加
Zhihu Data Analysis Training Camp
ping的原理
企业应当实施的5个云安全管理策略
直击面试!阿里金九银十最新面试小册 稳过!
LeetCode每日一题(858. Mirror Reflection)
外置USB供电与内置锂电池供电自动切换电路
深度学习------pytorch实现cifar10数据集
正则表达式









