首页 > ACM题库 > HDU-杭电 > HDU 3050-Cat Jim-待解决
2014
02-27

HDU 3050-Cat Jim-待解决

Cat Jim

问题描述 :

Long long ago,there was a very big forest, called Happy Forest. In the forest, there was a very naughty cat, named Jim. One day, when Jim played in the forest, he was attracted by a beautiful butterfly and followed the butterfly, he went into the dire area, the Black ForestAn evil wizard lived in the Black Forest, he would kill anyone who entered the forest, and had a good meal with their bodies. Obviously, Jim knew what would happen to him. As a clever cat, Jim came up an idea quickly, that is, calling for help.

Unfortunately, the wizard trapped Jim with a magic called Maze, and then he went home prepered for the delicious cat-meet-dinner. He would come back at time T.

The magic Maze transmits somebody to a special square. At there, one must solve a riddle to get out, or waiting for powerful wizard to dispel the Maze.

On the square, there are N rows stone. Each row has M stones. Each stone has its own number, and there are M pieces of stone whose number is k(1<=k<=N). Only all the stone in kth row has the same number k, the person can exit the Maze.

Certainly, Jim didn’t want to become a cat-meet-dinner, so he asked you for help.

You can assume Jim would take 1 time from one row to any row (nomatter he took a stone or not), and when start (time 0), he could go to any row he likes.

Notice: even Jim can get out of magic Maze, he also need at least 1 time to call for help.(After that he would save by SuperCat and Wizard would lost his cat-meet-dinner. Clearly he might be crazy and do something terrible. For exmaple, he might summon some vampire to catch the cat Jim and then destroy the Happy Forest:( After all, he was a dread wizard.)

输入:

The first line contains N (the number of row, 1<=N<=10000), M (the number of stone in each row, 1<=M<=100), T(the time mentioned before, T<=2^32), Each of the next N lines contains M numbers in the range from 1 to N. The numbers are separated with a space.

输出:

The first line contains N (the number of row, 1<=N<=10000), M (the number of stone in each row, 1<=M<=100), T(the time mentioned before, T<=2^32), Each of the next N lines contains M numbers in the range from 1 to N. The numbers are separated with a space.

样例输入:

4 3 10
1 3 1
2 3 3
1 2 2
4 4 4
4 3 1
1 3 1
2 3 3
1 2 2
4 4 4

样例输出:

6
6
Poor Cat

  1. “再把所有不和该节点相邻的节点着相同的颜色”,程序中没有进行不和该节点相邻的其他节点是否相邻进行判断。再说求出来的也不一样是颜色数最少的

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  3. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?