CF267B.Dominoes
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touch with the sides that had the same number of points? You can rotate the dominoes, changing the left and the right side (domino "1-4" turns into "4-1").
你有一组多米诺骨牌。每张多米诺骨牌是一块矩形瓷砖,其表面被一条线分成两个正方形端面。你能否将所有多米诺骨牌从左到右依次排成一行,使得任意两张相邻的多米诺骨牌相接触的端面所带的点数相同?你可以旋转多米诺骨牌,从而交换其左右端面(例如,多米诺骨牌“1-4”可变为“4-1”)。
输入格式
The first line contains the number n (1 ≤ n ≤ 100). Next n lines contain the dominoes. Each of these lines contains two numbers — the number of points (spots) on the left and the right half, correspondingly. The numbers of points (spots) are non-negative integers from 0 to 6. Duplicates (identical tiles) may be present in the given set.
第一行包含一个整数 n(1≤n≤100)。接下来的 n 行描述了多米诺骨牌。每行包含两个数字——分别表示该骨牌左半部分和右半部分的点数(即圆点数)。点数为 0 到 6 之间的非负整数。给定的骨牌集合中可能包含重复(完全相同的骨牌)。
输出格式
Print "No solution", if it is impossible to arrange the dominoes in the required manner. If the solution exists, then describe any way to arrange the dominoes. You put the dominoes from left to right. In each of the n lines print the index of the domino to put in the corresponding position and then, after a space, the character "+" (if you don't need to turn the domino) or "–" (if you need to turn it).
如果无法按要求排列多米诺骨牌,则输出“No solution”。如果存在解,则描述一种可行的多米诺骨牌排列方式。你需要从左到右放置多米诺骨牌。在接下来的 n 行中,每行输出一个整数(表示应放在该位置的多米诺骨牌的索引),后跟一个空格,再跟一个字符 “+”(表示无需翻转该多米诺骨牌)或 “–”(表示需要翻转该多米诺骨牌)。
输入输出样例
输入#1
5 1 2 2 4 2 4 6 4 2 1
输出#1
2 - 1 - 5 - 3 + 4 -
输入解题思路,AI测评打分。不知道怎么写?