欢迎光临散文网 会员登陆 & 注册

CF1842A - Tenzing and Tsondu

2023-06-25 11:27 作者:您是打尖儿还是住店呢  | 我要投稿

Olympus City recently launched the production of personal starships. Now everyone on Mars can buy one and fly to other planets inexpensively.

Each starship has a number —some positive integer x. Let's define the luckiness of a number x as the difference between the largest and smallest digits of that number. For example, 142857 has 8

 as its largest digit and 1 as its smallest digit, so its luckiness is 8−1=7. And the number 111 has all digits equal to 1, so its luckiness is zero.

Hateehc is a famous Martian blogger who often flies to different corners of the solar system. To release interesting videos even faster, he decided to buy himself a starship. When he came to the store, he saw starships with numbers from l to r inclusively. While in the store, Hateehc wanted to find a starship with the luckiest number.

Since there are a lot of starships in the store, and Hateehc can't program, you have to help the blogger and write a program that answers his question.

-------------------------------------------------------------------中文:

奥林巴斯城最近启动了个人星舰的生产。 现在火星上的每个人都可以购买一架并以便宜的价格飞往其他星球。

每艘星舰都有一个数字——某个正整数 x。 让我们将数字 x 的幸运值定义为该数字的最大数字和最小数字之间的差。 例如,142857 有 8 个

  最大的数字是 1,最小的数字是 1,所以它的幸运是 8−1=7。 而数字111的所有数字都等于1,因此它的幸运值为零。

Hateehc是一位著名的火星博主,经常飞往太阳系的不同角落。 为了更快地发布有趣的视频,他决定给自己买一艘星际飞船。 来到店里,他看到了一艘艘编号从l到r(含)的星舰。 在商店里,Hateehc 想要找到一艘拥有最幸运数字的星舰。

由于商店里有很多星舰,而 Hateehc 不会编程,所以你必须帮助博主编写一个程序来回答他的问题。

--------------------------------------------------------题解

判断是否是lucky 数字,依次去遍历即可,但是最大只能是9,所以在r值的选择就可以去math.min(l+100,r)因为只要差值只要超过100的话,最大值就一定是9了;

下面是代码:


CF1842A - Tenzing and Tsondu的评论 (共 条)

分享到微博请遵守国家法律