当前位置:网站首页>LeetCode每日一题(858. Mirror Reflection)
LeetCode每日一题(858. Mirror Reflection)
2022-08-04 11:56: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
把房间想象成一个电梯, 电梯的所有 m * p(m 为大于 0 的整数)的高度处左右两边都挂着传感器, 奇数层挂 2 和 1, 偶数层挂 2 和 0,然后这个题就变成了求最小公倍数的题
impl Solution {
pub fn mirror_reflection(p: i32, q: i32) -> i32 {
let mut m = 1;
let mut is_up = true;
loop {
if p * m % q == 0 {
if p * m / q % 2 == 0 {
return 2;
}
if is_up {
return 1;
}
return 0;
}
m += 1;
is_up = !is_up;
}
}
}
边栏推荐
- SchedulX V1.5.0发布,提供快速压测、对象存储等全新功能!
- 请 AI 画家弄了个 logo,网友热议:画得非常好,下次别画了!
- Leetcode brush questions - 543. Diameter of binary trees, 617. Merging binary trees (recursive solution)
- 小程序实战(一)- 骨架屏的应用与实现
- #夏日挑战赛#OpenHarmony 给你的输入法加点彩—星球崛起
- TPC藏宝计划IDO自由协议复利模式开发功能分析
- BOSS直聘回应女大学生连遭两次性骚扰:高度重视求职者安全 可通过App等举报
- exness:美联储重现鹰派口吻,黄金承压面临转跌信号
- 动手学深度学习_LeNet
- 【目标检测】yolov3特征提取网络------Darknet53网络及pytorch实现
猜你喜欢
技术分享| 融合调度系统中的电子围栏功能说明
Xilinx VIVADO 中 DDR3(Naive)的使用(1)创建 IP 核
Transferring Rich Feature Hierarchies for Robust
Leetcode刷题——二叉搜索树相关题目(98. 验证二叉搜索树、235. 二叉搜索树的最近公共祖先、1038. 从二叉搜索树到更大和树、538. 把二叉搜索树转换为累加树)
知道创宇EDR系统实力通过中国信通院端点检测与响应产品能力评测
能力更强,医疗单据识别+医疗知识库校验
数据库表列类型;DML_添加数据;DDL_修改,删除数据库表
God Space - the world's first Web3.0-based art agreement creative platform, broadening the boundaries of multi-art integration
项目管理前景
Tapdata 开源项目基础教程:功能特性及实操演示
随机推荐
揭秘交换机市场内幕,“准工业级”猫腻你中招了吗?
ECCV 2022 | Towards Data Efficient Transformer Object Detectors
力扣解法汇总1403-非递增顺序的最小子序列
Leetcode Brush Questions - Path Sum
Leetcode刷题——543. 二叉树的直径、617. 合并二叉树(递归解决)
独立站卖家如何使用 WhatsApp Business API 建立有意义的客户关系?
IBM Q复制新增QSUB
国际原子能机构总干事警告称扎波罗热核电站安全形势已“完全失控”
小程序实战(三) - head组件的封装与使用
深度学习------pytorch实现划拳模型训练
The use of DDR3 (Naive) in Xilinx VIVADO (2) Read and write design
企业应当实施的5个云安全管理策略
The use of DDR3 (Naive) in Xilinx VIVADO (3) simulation test
Zikko launches new Thunderbolt 4 docking station with both HDMI2.1 and 2.5GbE
POJ2367Genealogical tree题解
ESP8266-Arduino编程实例-MQ3酒精传感器驱动
ECCV 2022 | 通往数据高效的Transformer目标检测器
终于有人把分布式机器学习讲明白了
#夏日挑战赛#OpenHarmony 给你的输入法加点彩—星球崛起
Leetcode brush questions - binary search tree related topics (98. Verify binary search tree, 235. The nearest common ancestor of binary search tree, 1038. From binary search tree to bigger sum tree, 5