#P2593. [ZJOI2006] 超级麻将

    ID: 1606 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2006各省省选浙江哈希,HASH

[ZJOI2006] 超级麻将

Description

Many people know how to play Mahjong; of course, some do not. Don’t worry, here is a brief introduction to the rules.

In standard Mahjong, there are three suits: "Tong", "Suo", and "Wan". Each suit has numbers 191\sim9, and there are four copies of each identical tile. For example, 1Tong~9Tong, 1Suo~9Suo, and 1Wan~9Wan each have 44 copies, so there are 36×3=10836\times 3=108 tiles in total. When someone wins, each player has 1414 tiles. A winning hand consists of several melds (either three consecutive tiles of the same suit, or three identical tiles), plus one pair. Of course, if the hand consists entirely of pairs, called “Seven Pairs”, it is also a winning hand. The figure below shows an example of three in sequence.

To judge whether someone can win, an obviously naive algorithm would do. A Mahjong fanatic from a middle school informatics club thought about it and decided to modify standard Mahjong into Super Mahjong.

In Super Mahjong, there is no distinction between suits. The number on each tile can be 11001\sim100, and there are 100100 copies of each number. What’s more, players are free to hold as many tiles as they like. Exciting!

Exciting as it is, how do you form a winning hand with many tiles?

Super Mahjong defines that a hand is winning if the tiles can be partitioned into several melds (one meld can be three consecutive numbers, one tile each; or three or four identical numbers also count as one meld), plus one pair of identical tiles.

As an informatics contestant, please write a program to determine whether the player can win.

Input Format

The first line contains an integer N(N100)N(N\le 100), indicating that Super Mahjong was played NN times.

The next NN lines each contain 100100 numbers a1a100a_1 \dots a_{100}, describing the counts of each tile number in that round. aia_i means there are aia_i tiles with number ii. (0ai100)(0\le a_i\le 100)

Output Format

Output NN lines. Print Yes if it is a winning hand; otherwise print No. Note the case of Yes and No.

3
2 4 0 0 0 0 0 …… 0(一共98个0)
2 4 2 0 0 0 0 …… 0(一共97个0)
2 3 2 0 0 0 0 …… 0(一共97个0)
Yes
Yes
No

Hint

Translated by ChatGPT 5