B*******1 发帖数: 2454 | 1 careercup上面看到过2题类似的来自amazon的了。
- You are given two 4 digits prime numbers N1 and N2,
- You can change only one digit of N1 at a time.
- Resultant of changing a digit of N1 should also be a prime number.
How many number of digit changes (minimum) are required to convert N1 to N2?
Example:
Assume (8785, 8787, 8887, 9887, 9897) are prime numbers.
Lets say N1=8785 and N2 = 9897 then
change-1: 8785 => 8787
change-2: 8787 => 8887
change-3: 8887 => 9887
change-4: 9887 => 9897
So 4 digit changes are require to convert N1 to N2.
这题是不是要建图,然后bfs啊,有更加好的办法吗? | g**********y 发帖数: 14569 | 2 这个没什么技巧可以用,就是直接建个4位的素数表,然后BFS。 | B*******1 发帖数: 2454 | |
|