荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: kaman (天外飞仙), 信区: ACMICPC
标  题: 一道题
发信站: 荔园晨风BBS站 (Sat Apr 17 12:03:42 2004), 站内信件

的确是简单题,但要看所用的策略,怎样在最少的时间里做出来
Runaround Numbers

Runaround numbers are integers with unique digits, none of which is zero
 (e.g., 81362) that also have an interesting property, exemplified by
this demonstration:

If you start at the left digit (8 in our number) and count that number
of digits to the right (wrapping back to the first digit when no
digits on the right are available), you'll end up at a new digit (a
number which does not end up at a new digit is not a Runaround Number).
 Consider: 8 1 3 6 2 which cycles through eight digits: 1 3 6 2 8 1 3
6 so the next digit is 6.
Repeat this cycle (this time for the six counts designed by the `6') and
 you should end on a new digit: 2 8 1 3 6 2, namely 2.
Repeat again (two digits this time): 8 1
Continue again (one digit this time): 3
One more time: 6 2 8 and you have ended up back where you started, after
 touching each digit once. If you don't end up back where you started
after touching each digit once, your number is not a Runaround number.
Given a number M (that has anywhere from 1 through 9 digits), find and
print the next runaround number higher than M, which will always fit
into an unsigned long integer for the given test data.

PROGRAM NAME: runround
INPUT FORMAT
A single line with a single integer, M
SAMPLE INPUT (file runround.in)
81361

OUTPUT FORMAT
A single line containing the next runaround number higher than the input
 value, M.
SAMPLE OUTPUT (file runround.out)
81362

--
Long long ago,there is a hero stand at the edge of the land,a sword in
hand.......
       ︵~`   ╭)                          ▁▁
      ︸ヾ)    (╯                        ▕天外▏
      ゞ7(  ︵  ))                        ▕飞仙▏
       ╰ ︶へ︶╯                          ▔▔
       ヅ╯  ジ〉

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.111.200]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店