1. 程式人生 > >[acm.sgu.ru]101. Domino

[acm.sgu.ru]101. Domino

101. Domino

time limit per test: 0.25 sec.
memory limit per test: 4096 KB

Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The blocks usually are called bones, dominoes, or pieces and sometimes men, stones, or even cards.
The face of each piece is divided, by a line or ridge, into two squares, each of which is marked as would be a pair of dice...

The principle in nearly all modern dominoes games is to match one end of a piece to another that is identically or reciprocally numbered.

ENCYCLOPÆDIA BRITANNICA

Given a set of domino pieces where each side is marked with two digits from 0 to 6. Your task is to arrange pieces in a line such way, that they touch through equal marked sides. It is possible to rotate pieces changing left and right side.

Input

The first line of the input contains a single integer N (1 ≤ N ≤ 100) representing the total number of pieces in the domino set. The following N lines describe pieces. Each piece is represented on a separate line in a form of two digits from 0 to 6 separated by a space.

Output

Write “No solution” if it is impossible to arrange them described way. If it is possible, write any of way. Pieces must be written in left-to-right order. Every of N lines must contains number of current domino piece and sign “+” or “-“ (first means that you not rotate that piece, and second if you rotate it).

Sample Input

5
1 2
2 4
2 4
6 4
2 1

Sample Output

2 -
5 +
1 +
3 +
4 -

思路:

由於英文水平有限,沒看懂什麼意思,請來了各種翻譯軟體,雖看懂了字面,但不理解,搜尋網際網路的結果多是一句話帶過:這就是個一筆畫問題!然後就各種程式碼……我很無語……

現在解釋題目意思:這就是一個一筆畫問題!不懂的用翻譯!!

呃……好了,我好好說:多米諾骨牌效應大家都知道(不知道的看視訊這個我就不貼了),現在就是說,一張骨牌上有兩面,分別寫了0~6中的一個字。骨牌擺放的規則是:兩個相臨骨牌的相對的兩個面的數字要相同,不然不能擺放。比如:3張牌(0,1)(1,2)(2,6)或(3,5)(5,2)(2,4)。反正相臨兩個牌相對的兩個面都是相同數字就對了。

規則說完,說輸入:

第一行是骨牌數(不解釋)

接下來N行是每個骨牌的兩面刻的數字。

輸出:

如何將這些牌擺放成一條線呢?如果能擺成,輸出骨牌的順序號(就是輸入時骨牌的序號,從1開始)如果該骨牌要翻轉(本來是1,3,現在放的時候要放成3,1)那麼就在序號後輸出一個‘-’號,否則,輸出‘+’號。

CODE:


參考文章:

http://isolvedaproblem.blogspot.jp/2011/08/sgu-101-domino.html

http://www.cnblogs.com/markliu/archive/2012/07/28/2613253.html

http://www.cnblogs.com/zhourongqing/archive/2012/09/18/2690185.html