2020牛客暑期多校训练营(第八场)G Game SET

链接:https://ac.nowcoder.com/acm/contest/5673/G
来源:牛客网

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 [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 \textbf{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,
[three][diamond][solid][red]
[two][squiggle][solid][green]
[one][oval][solid][purple]
form a \textbf{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, [*][diamond][solid][red] can be regarded as [one][diamond][solid][red], [two][diamond][solid][red] or [three][diamond][solid][red].

You’re given N unique cards, you need to find any valid set. Each card is used at most once.

示例1
输入

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

题意:
你需要找到三行 ,每一列的值都不一样,或者每一列的值都一样的组合,并且输出他们。
题解:
开始看着这个数据啊256 * 256 * 256*1000 ++,贼大然后莫名其妙的暴力过了,然后= = 赛后意识到他最多就只有四个参数,最多20个不能组成一个set。= =那么就是模拟他喽
三个for暴力跑,先把字符串处理成数字
Code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0),eps=1e-8;
const int maxn=300;
 
int n;
struct node
{
    int a[5];
} thi[maxn];
map<node,vector<int> >mp;
inline void f()
{
    string s;
    cin>>n;
    for(int k=1; k<=n; k++)
    {
        cin>>s;
        int l=s.size();
        int flag=0;
        string tmp;
        for(int i=0; i<l; i++)
        {
            if(s[i]=='[')
            {
                flag++;
                continue;
            }
            if(s[i]==']')
            {
                if(flag==1)
                {
                    if(tmp=="one")
                    {
                        thi[k].a[flag]=1;
                    }
                    if(tmp=="two")
                    {
                        thi[k].a[flag]=2;
                    }
                    if(tmp=="three")
                    {
                        thi[k].a[flag]=3;
                    }
                    if(tmp=="*")
                    {
                        thi[k].a[flag]=0;
                    }
                }
                else if(flag==2)
                {
                    if(tmp=="diamond")
                    {
                        thi[k].a[flag]=1;
                    }
                    if(tmp=="squiggle")
                    {
                        thi[k].a[flag]=2;
                    }
                    if(tmp=="oval")
                    {
                        thi[k].a[flag]=3;
                    }
                    if(tmp=="*")
                    {
                        thi[k].a[flag]=0;
                    }
                }
                else if(flag==3)
                {
                    if(tmp=="solid")
                    {
                        thi[k].a[flag]=1;
                    }
                    if(tmp=="striped")
                    {
                        thi[k].a[flag]=2;
                    }
                    if(tmp=="open")
                    {
                        thi[k].a[flag]=3;
                    }
                    if(tmp=="*")
                    {
                        thi[k].a[flag]=0;
                    }
                }
                else if(flag==4)
                {
                    if(tmp=="red")
                    {
                        thi[k].a[flag]=1;
                    }
                    if(tmp=="green")
                    {
                        thi[k].a[flag]=2;
                    }
                    if(tmp=="purple")
                    {
                        thi[k].a[flag]=3;
                    }
                    if(tmp=="*")
                    {
                        thi[k].a[flag]=0;
                    }
                }
                tmp.clear();
                continue;
            }
            if(flag)
            {
                tmp+=s[i];
            }
        }
    }
//    for(int i=1;i<=n;i++){
//      mp[thi[i]].push_back(i);
//  }
}
 
int solve(int l,int r)
{
    int ta[5];
    for(int i=1; i<=4; i++)
    {
        if(thi[l].a[i]=='*'||thi[r].a[i]=='*')
        {
            ta[i]=5;
        }
        else if(thi[l].a[i]==thi[r].a[i])
        {
            ta[i]=thi[l].a[i];
        }
        else
        {
            ta[i]=3^thi[l].a[i]^thi[r].a[i];
        }
    }
 
 
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    int t;
    cin>>t;
    for(int cas=1; cas<=t; cas++)
    {
        f();
        int flag=0;
        for(int i=1; i<=n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                int num[5]= {0};
                for(int k=1; k<=4; k++)
                {
                    if(thi[i].a[k]==0||thi[j].a[k]==0)
                    {
                        num[k]=6;
                        continue;
                    }
                    if(thi[i].a[k]==thi[j].a[k])
                    {
                        num[k]=thi[i].a[k];
                    }
                    else
                    {
                        num[k]=6-thi[i].a[k]-thi[j].a[k];
                    }
                }
                for(int k=j+1; k<=n; k++)
                {
                    int ff=1;
                    for(int mm=1; mm<=4; mm++)
                    {
                        //printf("%d %d %d %d %d\n",i,j,k,thi[k].a[mm],num[mm]);
                        if(num[mm]==6||thi[k].a[mm]==0)
                            continue;
 
                        if(thi[k].a[mm]!=num[mm])
                        {
                            ff=0;
                            break;
                        }
                    }
                    //printf("\n");
                    if(ff)
                    {
                        printf("Case #%d: %d %d %d\n",cas,i,j,k);
                        flag=1;
                        break;
                    }
                }
                if(flag)
                    break;
            }
            if(flag)
                break;
        }
        if(!flag)
        {
             printf("Case #%d: -1\n",cas);
        }
    }
    return 0;
}
/*
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]
[*][*][*][*]
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值