[acm.sgu.ru]101. Domino

版权声明:版权声明:本文为博主原创(剽窃)文章,未经博主允许不得不转载。 https://blog.csdn.net/kevinzhongzk/article/details/51406425

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



猜你喜欢

转载自blog.csdn.net/kevinzhongzk/article/details/51406425