一行代码就能解决的算法题 :: labuladong的算法小抄 #1077
Replies: 13 comments 4 replies
-
Nim游戏的本质似乎还能够更进一步解释。 推而广之,如果最少拿 1 个,最多拿 n个,其实就换成了凑n+1 的整数倍问题。 |
Beta Was this translation helpful? Give feedback.
-
电灯开关问题 就假设现在总共有 16 盏灯,我们求 16 的平方根,等于 4,这就说明最后会有 4 盏灯亮着,它们分别是第 11=1 盏、第 22=4 盏、第 33=9 盏和第 44=16 盏。 能否解释下第 15 个灯的情况,为什么是偶数次呢 |
Beta Was this translation helpful? Give feedback.
-
忽略上述问题,明白了,15 = 1×15 = 15x1 |
Beta Was this translation helpful? Give feedback.
-
15 = 3 ✖️ 5 被你吃了吗(⊙o⊙)… |
Beta Was this translation helpful? Give feedback.
-
电灯开关的问题不是很懂。。。废废的了 |
Beta Was this translation helpful? Give feedback.
-
打卡,感谢楼主! |
Beta Was this translation helpful? Give feedback.
-
稍微思考一下,没思考出来啊?谁能解释一下小于等于根号n的所有正整数的平方就是最好亮着的灯的索引... |
Beta Was this translation helpful? Give feedback.
-
哦哦哦,明白了,小于等于根号n,所以平方之后小于等于n,这也就是在算1-n有多少个平方数,而每个平方数索引处的灯都会被操作奇数次,所以一定是最后亮着的灯,非平方数的索引位置处的灯由于以根号非平方数为界限总有成对的因子出现,这将导致该灯会被操作偶数次,也就是灯灭,谢谢东哥 |
Beta Was this translation helpful? Give feedback.
-
就是算能完全开方的下标数量,不能完全开方的第i盏灯因子一定是偶数个,能完全开方的第i盏灯因子一定是奇数个 |
Beta Was this translation helpful? Give feedback.
-
@gaofeiseu16盏灯的情况下, 第15个灯被按了一共4次(1x15, 3x5), 也就是偶数次, 所以最后是灭的: |
Beta Was this translation helpful? Give feedback.
-
灯泡开关的问题,个人理解: |
Beta Was this translation helpful? Give feedback.
-
灯泡最后开着的条件就是被操作奇数次,对于第i个灯泡来说,能被操作机会只能是它的第约数次操作,比如说:第6个灯泡,能被操作的次数是 1, 2 , 3 ,6,发现都输成对出现的,6=23, 6=16,什么情况下能够出现奇数的情况呢?那就是i能够开完全平方 比如:4. 4=14, 4=22 ,那么4的约数就是1, 4 ,2。所以说只需要找n个灯泡,有多少个能够开完全平方的即可。因为他们被操作的次数只会是奇数次,而根据数学推论,小于等于n能够开完全平方的数字的个数为n的平方根。 |
Beta Was this translation helpful? Give feedback.
-
石头问题其实就是树. 算树两边哪边节点加起来大就选哪边. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
文章链接点这里:一行代码就能解决的算法题
评论礼仪 见这里,违者直接拉黑。
Beta Was this translation helpful? Give feedback.
All reactions