现在的位置: 首页 > 综合 > 正文

101. Domino

2018年01月22日 ⁄ 综合 ⁄ 共 1427字 ⁄ 字号 评论关闭
文章目录


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 followingN 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 -

有n块多米诺骨牌,每张牌的两面分别是0~6的数字,我们可以重新排列这些骨牌的顺序,并决定是否翻转这些骨牌,(翻转用'-'表示),输出一种可行的方案
样例的理解 :    4 2  2 1  1 2  2 4  4 6

建7个点分别为 0 1 2 3 4 5 6,以每张骨牌为一条边,每条边只走一次即一条欧拉路径,如果度为1的点少于等于2个且图是联通的,那么就可行。接下来从任意一个度为1的点开始遍历,如果原来有这条边输出端点和'+',没有这条边输出端点和'-'

【上篇】
【下篇】

抱歉!评论已关闭.