原题题面
S
E
T
SET
SET is a real-time card game designed by Marsha Falco in 1974 and published by Set Enterprises in 1991. The deck consists of 81 unique cards that vary in four features across three possibilities for each kind of feature: number of shapes (one, two, or three), shape (diamond, squiggle, or oval), shading (solid, striped, or open), and color (red, green, or purple). Each possible combination of features (e.g. a card with
[
t
h
r
e
e
]
[
d
i
a
m
o
n
d
]
[
s
t
r
i
p
e
d
]
[
g
r
e
e
n
]
[three][diamond][striped][green]
[three][diamond][striped][green])appears as a card precisely once in the deck.
In the game, certain combinations of three cards are said to make up a
s
e
t
set
set. For each one of the four categories of features — color, number, shape, and shading — the three cards must display that feature as a) either all the same, or b) all different. Put another way: For each feature the three cards must avoid having two cards showing one version of the feature and the remaining card showing a different version.
For example,
[
t
h
r
e
e
]
[
d
i
a
m
o
n
d
]
[
s
o
l
i
d
]
[
r
e
d
]
[three][diamond][solid][red]
[three][diamond][solid][red]
[
t
w
o
]
[
s
q
u
i
g
g
l
e
]
[
s
o
l
i
d
]
[
g
r
e
e
n
]
[two][squiggle][solid][green]
[two][squiggle][solid][green]
[
o
n
e
]
[
o
v
a
l
]
[
s
o
l
i
d
]
[
p
u
r
p
l
e
]
[one][oval][solid][purple]
[one][oval][solid][purple]
form a
s
e
t
set
set, because the shadings of the three cards are all the same, while the numbers, the colors, and the shapes among the three cards are all different.
There are some special cards which called Wild cards. Some values of a Wild card’s features can be wild, i.e they can take any value the player chooses. For example,
[
∗
]
[
d
i
a
m
o
n
d
]
[
s
o
l
i
d
]
[
r
e
d
]
[*][diamond][solid][red]
[∗][diamond][solid][red] can be regarded as
[
o
n
e
]
[
d
i
a
m
o
n
d
]
[
s
o
l
i
d
]
[
r
e
d
]
[one][diamond][solid][red]
[one][diamond][solid][red],
[
t
w
o
]
[
d
i
a
m
o
n
d
]
[
s
o
l
i
d
]
[
r
e
d
]
[two][diamond][solid][red]
[two][diamond][solid][red],
[
t
h
r
e
e
]
[
d
i
a
m
o
n
d
]
[
s
o
l
i
d
]
[
r
e
d
]
[three][diamond][solid][red]
[three][diamond][solid][red].
You’re given
N
N
N unique cards, you need to find any valid
s
e
t
set
set. Each card is used at most once.
输入描述
The first line of the input gives the numbers of test cases
T
T
T test cases follow.
Each test case consists of one line with one integer
N
N
N as described above.
The
i
t
h
ith
ith of the next
N
N
N lines describes the
i
−
t
h
i-th
i−th card. It contains four categories features, in the format of
[
n
u
m
b
e
r
]
[
s
h
a
p
e
]
[
s
h
a
d
i
n
g
]
[
c
o
l
o
r
]
[number][shape][shading][color]
[number][shape][shading][color]. The “
∗
*
∗” means wild value for that feature.
. The “*” means wild value for that feature.
There are no identical cards.
1
≤
T
≤
1000.
1\leq T \leq 1000.
1≤T≤1000.
1
≤
N
≤
256.
1\leq N \leq 256.
1≤N≤256.
输出描述
For each test case,
C
a
s
e
#
x
:
−
1
Case \#x: −1
Case#x:−1 if they can not make up a
s
e
t
set
set,
otherwise, print
C
a
s
e
#
x
:
y
1
y
2
y
3
Case \#x: y1 y2 y3
Case#x:y1y2y3, where x is the test case number (starting from 1) and y1 y2 y3 are the indexes of cards (starting from 1) that can make up a
s
e
t
set
set. If there are several solutions, output any of them.
输入样例
3
3
[three][diamond][solid][red]
[two][*][solid][*]
[two][*][*][red]
5
[one][diamond][open][red]
[two][squiggle][solid][red]
[two][squiggle][*][red]
[two][diamond][solid][red]
[three][diamond][*][red]
6
[one][diamond][open][red]
[two][squiggle][*][green]
[two][squiggle][solid][green]
[two][diamond][solid][green]
[three][diamond][*][red]
[*][*][*][*]
输出样例
Case #1: -1
Case #2: 1 4 5
Case #3: 1 2 6
题面分析
简单粗暴模拟题。
一种牌有四个属性:数字、形状、纹理、颜色。每种属性各可能有三种不同情况,"
∗
*
∗"代表任意情况。
从牌堆里拿出三张牌,如果彼此的四个属性都相同或两两都不同则合法。
请找出一对合法情况,没有合法情况直接出-1。
在处理的技巧上,可以把
∗
*
∗当做0,其他的当做1,2,3,判断时先判断三个数的属性相乘是否为0,如果是0则一定合法
(两个0自然成立,1个0时不论是剩下俩不等还是相等都能让*构造成想要的样子)
AC代码(1838ms)
import java.util.*;
/**
* @author DrGilbert
* 其实还是有很多地方可以优化...将就下吧
*/
class Card
{
int number;
int shape;
int color;
int shading;
}
public class Main
{
public static int equal (int a,int b)
{
if(a==b)
{
return 1;
}
return -1;
}
public static boolean equal2(int a,int b,int c)//判断每个属性
{
if(a*b*c==0)//有任意*的情况了
return true;
if(equal (a,b)==1 && equal (b,c)==1)//相同
{
return true;
}
if(equal (a,b)!=1 && equal (b,c)!=1 && equal (a,c)!=1)//不同
{
return true;
}
return false;
}
public static boolean check(Card a,Card b,Card c)//判断三张牌
{
if(equal2 (a.shading,b.shading,c.shading) && equal2 (a.shape,b.shape,c.shape) && equal2 (a.number,b.number,c.number) && equal2 (a.color,b.color,c.color))
{
return true;
}
return false;
}
public static void main (String[] args)
{
Card[] cards = new Card[300];
Scanner cin = new Scanner (System.in);
int t = cin.nextInt ();
for (int z = 1;z <= t;z++)
{
// System.out.println ();
int n = cin.nextInt ();
for (int i = 1;i <= n;i++)
{
cards[i]=new Card ();
String s;
s = cin.next ();
s = s.replace ("]["," ");
s = s.replace ("[","");
s=s.replace ("]","");
// System.out.println (s);
String[] ss = s.split (" ");
// System.out.println (ss.length);
switch (ss[0])
{
case "one":
{
cards[i].number = 1;
break;
}
case "two":
{
cards[i].number = 2;
break;
}
case "three":
{
cards[i].number = 3;
break;
}
default:
{
cards[i].number = 0;
break;
}
}
switch (ss[1])
{
case "diamond":
{
cards[i].shape = 1;
break;
}
case "squiggle":
{
cards[i].shape = 2;
break;
}
case "oval":
{
cards[i].shape = 3;
break;
}
default:
{
cards[i].shape = 0;
break;
}
}
switch (ss[2])
{
case "solid":
{
cards[i].shading = 1;
break;
}
case "striped":
{
cards[i].shading = 2;
break;
}
case "open":
{
cards[i].shading = 3;
break;
}
default:
{
cards[i].shading = 0;
break;
}
}
switch (ss[3])
{
case "red":
{
cards[i].color = 1;
break;
}
case "green":
{
cards[i].color = 2;
break;
}
case "purple":
{
cards[i].color = 3;
break;
}
default:
{
cards[i].color = 0;
break;
}
}
// System.out.printf ("%d %d %d %d\n",cards[i].number,cards[i].shape,cards[i].shading,cards[i].color);
}
boolean flag=false;
for(int i=1;i<=n-2 && !flag;i++)
{
for (int j=i+1;j<=n-1 && !flag;j++)
{
for(int k=j+1;k<=n && !flag;k++)
{
if(check(cards[i],cards[j],cards[k]))
{
System.out.printf ("Case #%d: %d %d %d\n",z,i,j,k);
flag=true;
}
}
}
}
if(!flag)
{
System.out.printf ("Case #%d: -1\n",z);
}
}
}
}
后记
男人的嘴骗人的鬼
DrGilbert 2020.8.3