CTU Open Contest 2016 H. It's Raining, Man 模拟 分类讨论

Walter is spending holidays at the farm of his great-grandfather. It is raining and raining and raining. Walter sits in the attic of an aged barn where he has found a pack of old poker cards among piles of various dusty junk. The cards look quite antiquated and interesting. He starts to lay down the cards one by one, side by side, on the floor when he suddenly notices that there appears to be some kind of order in their sequence. Many pairs of successive cards are either of the same rank or of the same suit. “This might be a nice little puzzle,” says Walter to himself. “I wonder if I can rearrange the sequence so that each two consecutive cards share either the rank or the suit. But wait, the pack looks to be incomplete, that might severely limit the arrangement possibilities, hmm...”

Help Walter determine whether his puzzle is solvable.

Input Specification

There are more test cases. Each test case consists of a single line on which all cards in the pack are listed. The list starts with one integer L (1 ≤ L ≤ 52), denoting the number of cards in the pack, followed by a space and L card descriptions. Each card is described by a two character string. The first character denotes the rank of the card (“A”=Ace, “2”–“9”, “X”=10, “J”=Jack,“Q”=Queen, “K”=King) and the second character denotes the suit of the card (“C”=Clubs,“D”=Diamonds, “H”=Hearts, “S”=Spades). The successive card descriptions are separated by one space.

Output Specification

For each test case, print a single line with the string “YES” if the puzzle is solvable or a line with the string “NO” if the puzzle is not solvable.

样例输入

8 2C 2D 2H 2S XC JS QS KS
4 5C 4H AS 9D

样例输出

YES
NO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值