编程介的小学生 2019-11-22 23:56 采纳率: 20.5%
浏览 78

Dominoes 程序设计问题

Problem Description
A domino contains two ends, each labeled with number between 1 and 6. You are to write a program that determines if a set of dominoes can be organized in a line so that all dominoes are used; numbers on successive dominoes match; and the numbers on both ends match. You are allowed to rearrange and flip the dominoes arbitrarily. For example, the five dominos: (3 3), (3 1), (4 3), (1 6), and (4 6) can be arranged as:

The five dominos: (4 5), (3 4), (1 2), (2 3), and (5 5) cannot be arranged with all ends matching.

Input
The input contains a list of domino-sets. The first line of each set contains a single integer corresponding to the number of dominos in the set – 3 <= N <= 10. The next N lines each contain the two values on a single domino. The end of input is denoted by N = 0.

Output
Your program should produce one line of output for every set of dominos. The format should be: “Set #1: YES” or “Set #1: NO”.

Sample Input
3
1 2
3 2
3 1
5
4 5
3 4
1 2
2 3
5 5
5
3 3
3 1
4 3
1 6
4 6
0

Sample Output
Set #1: YES
Set #2: NO
Set #3: YES

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作