poj 1053 Set Me

ACM比赛整理

共 5219字,需浏览 11分钟

 · 2021-12-13

Set Me


Description

The game of Set is played with a deck of eighty-one cards, each having the following four characteristics:
. Symbol: diamonds, ovals, or squiggles
. Count: 1, 2, or 3 symbols
. Color: red, green, or purple
. Shading: outlined, filled, or striped
The cards are shuffled and a tableau of twelve cards is laid out. Players then attempt to be the first to identify "sets" which exist in the tableau. Sets are removed as they are identified and new cards are dealt in their place. Play continues in this manner until all cards have been used. The winner is the player with the most sets.
A set is a collection of three cards in which each characteristic is either the same on all three cards or different on all three cards. For example, the cards shown below form a set.


To see how the cards above form a set, take each characteristic in turn. First, each card has different symbol: the first card has squiggles, the second diamonds, and the third ovals. Second, each card has the same count of symbols, three. Third each card has a different color, and finally, each card has a different shading. Thus, each characteristic is either the same on all three cards or different on all three cards, satisfying the requirement for a set.
Consider the following example of three cards which do not form a set.


Again, take each characteristic in turn. Each card has a different symbol, each card has a different count of symbols, and each card is the same color. So far this satisfies the requirements for a set. When the shading characteristic is considered, however, two cards are filled and one card is striped. Thus, the shading on all three cards is neither all the same nor all different, and so these cards do not form a set.

Input

The input for this program consists of several tableaus of cards. The tableaus are listed in the input file one card per line, with a single blank line between tableaus. The end of the input is marked by the end of the file. Each card in a tableau is specified by four consecutive characters on the input line. The first identifies the type of symbol on the card, and will be either a "D", "O", or "S", for Diamond, Oval, or Squiggle, respectively. The second character will be the digit 1, 2, or 3, identifying the number of symbols on the card. The third identifes the color and will be an "R", "G", or "P" for Red, Green, or Purple, respectively. The final character identifes the shading and will be an "O", "F", or "S" for Outlined, Filled, or Striped. All characters will be in uppercase.

Output

The output for the program is, for each tableau, a list of all possible sets which could be formed using cards in the tableau. The order in which the sets are output is not important, but your output should adhere to the format illustrated by the example below. In the event that no sets exist in a tableau, report "*** None Found ***".

Sample Input

S1PS
D3PO
S2GF
O2GS
O2GF
O3PO
S2RF
S3GS
D2GS
O1GS
O1GF
S2PS

O2GF
O1PF
D2PO
D3RO
S2PO
O1GF
O1GS
D2GO
S3PF
S2GF
D2GS
S1RS

Sample Output

CARDS:  S1PS D3PO S2GF O2GS O2GF O3PO S2RF S3GS D2GS O1GS O1GF S2PS
SETS: 1. D3PO S2RF O1GS
2. S3GS D2GS O1GS

CARDS: O2GF O1PF D2PO D3RO S2PO O1GF O1GS D2GO S3PF S2GF D2GS S1RS
SETS: *** None Found ***



设置我


描述

Set 游戏使用一副八十一张牌进行游戏,每张牌具有以下四个特征:
符号:菱形、椭圆形或波浪形
计数:1、2 或 3 个符号
颜色:红色、绿色或紫色
底纹:勾勒、填充或条纹
将卡片洗牌并布置成一张包含 12 张卡片的画面。然后,玩家尝试成为第一个识别画面中存在的“集合”的人。组合在被识别时被移除,并在它们的位置上发新牌。以这种方式继续游戏,直到用完所有卡片。获胜者是拥有最多套数的玩家。
一组是三张牌的集合,其中每张牌的特征要么在所有三张牌上都相同,要么在所有三张牌上都不同。例如,下面显示的卡片形成一组。


要查看上述卡片如何形成一组,请依次获取每个特征。首先,每张牌都有不同的符号:第一张牌有波浪线,第二张是菱形,第三张是椭圆。其次,每张牌都有相同的符号数,三个。第三,每张卡片都有不同的颜色,最后,每张卡片都有不同的阴影。因此,每个特征要么在所有三张牌上都相同,要么在所有三张牌上都不同,满足集合的要求。
考虑以下不形成集合的三张牌的示例。


再次,依次获取每个特征。每张牌都有不同的符号,每张牌的符号数不同,每张牌的颜色相同。到目前为止,这满足了集合的要求。然而,当考虑阴影特性时,两张卡片被填充,一张卡片被条纹化。因此,所有三张牌上的阴影既不完全相同也不完全不同,因此这些牌不形成一组。

输入

该程序的输入由几张卡片组成。表格在输入文件中每行一张卡片列出,表格之间有一个空行。输入的结尾由文件的结尾标记。表格中的每张卡片都由输入行上的四个连续字符指定。第一个标识卡片上的符号类型,分别是“D”、“O”或“S”,分别代表菱形、椭圆形或曲线形。第二个字符将是数字 1、2 或 3,用于标识卡片上的符号数量。第三个标识颜色,分别是红色、绿色或紫色的“R”、“G”或“P”。最后一个字符标识阴影,将是“O”、“F”或“S”,表示轮廓、填充或条纹。

输出

对于每个画面,该程序的输出是可以使用画面中的卡片形成的所有可能集合的列表。输出集合的顺序并不重要,但您的输出应遵循以下示例所示的格式。如果画面中不存在集合,则报告“*** 未找到 ***”。

Sample Input

S1PS
D3PO
S2GF
O2GS
O2GF
O3PO
S2RF
S3GS
D2GS
O1GS
O1GF
S2PS

O2GF
O1PF
D2PO
D3RO
S2PO
O1GF
O1GS
D2GO
S3PF
S2GF
D2GS
S1RS

Sample Output

CARDS:  S1PS D3PO S2GF O2GS O2GF O3PO S2RF S3GS D2GS O1GS O1GF S2PS
SETS: 1. D3PO S2RF O1GS
2. S3GS D2GS O1GS

CARDS: O2GF O1PF D2PO D3RO S2PO O1GF O1GS D2GO S3PF S2GF D2GS S1RS
SETS: *** None Found ***



代码:

#include 

using namespace std;

char cards[12][5];

//检查第p位是否符合条件
bool check_bit(int i, int j, int k, int p) {
if (cards[i][p] == cards[j][p] && cards[j][p] == cards[k][p]) {
return true;
}
if (cards[i][p] != cards[j][p] && cards[j][p] != cards[k][p]
&& cards[i][p] != cards[k][p]) {
return true;
}
return false;
}

//检查第i、j、k张牌的组合能否构成set
bool check(int i, int j, int k) {
if (check_bit(i, j, k, 0) && check_bit(i, j, k, 1)
&& check_bit(i, j, k, 2) && check_bit(i, j, k, 3)) {
return true;
}
return false;
}

int main(void) {
while (cin >> cards[0]) {
for (int i = 1; i < 12; ++i) {
cin >> cards[i];
}
cout << "CARDS: " << cards[0];
for (int i = 1; i < 12; ++i) {
cout << " " << cards[i];
}
cout << endl;
cout << "SETS: ";
int set_id = 0;
for (int i = 0; i < 12; ++i) {
for (int j = i + 1; j < 12; ++j) {
for (int k = j + 1; k < 12; ++k) {
if (check(i, j, k)) {
if (set_id >= 1) {
cout << " ";
}
cout << ++set_id << ". " << cards[i] << " "
<< cards[j] << " " << cards[k] << endl;
}
}
}
}
if (set_id == 0) {
cout << "*** None Found ***" << endl;
}
cout << endl;
}
return 0;
}


浏览 13
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报