当前位置:网站首页>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;}}}
边栏推荐
猜你喜欢
手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
【全网首发】Redis系列5:深入分析Cluster 集群模式
数据库表列类型;DML_添加数据;DDL_修改,删除数据库表
监督和半监督学习下的多标签分类综述
The use of DDR3 (Naive) in Xilinx VIVADO (2) Read and write design
Leetcode brush questions - 543. Diameter of binary trees, 617. Merging binary trees (recursive solution)
Transferring Rich Feature Hierarchies for Robust
多行函数;group_by分组;having分组后筛选;单表查询总结
中电资讯 - 一路“标”升,喜迎Q3开门红
论文翻译:2022_Time-Frequency Attention for Monaural Speech Enhancement
随机推荐
【目标检测】------yolo:xml和txt文件相互转化
The sword refers to the Great Wall Cannon?Official spy photos of Changan's new pickup
MOSFET米勒平台(Miller Plateau)
电源输出的Overshoot和Undershoot 测试
微信服务号调用API实现微信报警
yolov5——detect.py代码【注释、详解、使用教程】
Flutter 使用 json_serializable 解析 JSON 支持泛型
形态学(膨胀、腐蚀)
涨姿势了!原来这才是多线程正确实现方式
到底什么是JS原型
C#控制台退出前操作
使用函数
抗积分饱和PID控制器
划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板
直击面试!阿里金九银十最新面试小册 稳过!
ECCV 2022 | 通往数据高效的Transformer目标检测器
终于有人把分布式机器学习讲明白了
ESP8266-Arduino编程实例-TSL2561亮度传感器驱动
yolo系列的Neck模块
ping的原理