Magician Licensing Issues
Problem Description:
The magician used a deck of 13 black label, pre-lined them up and stacked together, face down. Said to the audience: "I do not look at cards, only a few can guess what each card is, I loudly count, you listen, do not believe?" Live demonstrations. "The magician put the top card number at 1, turn him over. It is a spade a, put the spades a on the table, the second number 1, 2, the first card placed under these cards, the second card turned over, just the Spades 2, also put it on the table in turn will be 13 cards all turned out, accurate.
Question: How is the start order of the cards arranged?
The idea is to use a circular list to solve the problem,
- Initializes a circular linked list with a length of 13, and the initialization value of each node is 0
- Count = 1~13 times, counting the number of cards to the corresponding count, for example, starting with head 1, then two times, head = Head.next.next, that is, the third is 2, and in the process of counting, the value of the node will not be counted.
Question of the Latin phalanx
The Latin phalanx is a nxn square in which there are n different elements, each of which has exactly n, and each element appears once in a row and column. The famous mathematician and physicist Euler used the Latin alphabet as a symbol of the elements of the Latin phalanx, and the Latin phalanx was thus named.
For example, a 3x3 Latin phalanx:
Ideas:
- First, the first row and the first column are set to 1~n, and then each row is populated by the Loop list method
- For example, the second line starts with 2, then the remaining padding is 3, 4, ... , n,1
- The third line starts with 3, then the remaining padding is 4, 5, ... , n,1,2, etc.
Magician's issue of licensing and the problem of Latin phalanx