Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力

A. Borya and Hanabi

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/442/problem/A

Description

Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.

Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has).

The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints.

A color hint goes like that: a player names some color and points at all the cards of this color.

Similarly goes the value hint. A player names some value and points at all the cards that contain the value.

Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.

Output

Print a single integer — the minimum number of hints that the other players should make.

Sample Input

2
G3 G3

Sample Output

0

HINT

题意

有一个人知道有哪些牌,但是不知道这些牌是哪张。

他每次可以问2个问题,

1.x颜色的牌是哪些

2.数值为y的牌是哪些

然后问最少多少次询问,这个人才能分清哪些牌是哪些

题解:

我们把这些牌抽象成二维空间的点,然后我们开始画线

如果这个平面上的点少于等于1个,那么我们就可以说明这个人已经分清了

那么哪些点我们可以删去呢?只要这个点被两条线段覆盖,或者这条线段上只有这么一个点,那么这个点就是可以被删除的

然后直接暴力搞就好了~

代码:

#include <cstdio>
#include <algorithm>
using namespace std;
int n,i,j,k,r,a[111],b[111],x[111],c[1111];
char s[7];
int main() 
{
    while(~scanf("%d",&n))
    {
        for (i=0; i<n; i++) 
        {
            scanf("%s",s);
            if (s[0]=='R') 
                a[i]=0;
            if (s[0]=='G') 
                a[i]=1;
            if (s[0]=='B') 
                a[i]=2;
            if (s[0]=='Y') 
                a[i]=3;
            if (s[0]=='W') 
                a[i]=4;
            b[i]=s[1]-'1';
        }
        for (r=10, i=0; i<(1<<10); i++) 
        {
            if(i) 
                c[i]=c[i/2]+(i&1);
            for(j=0; j<n; j++) 
            {
                x[j]=0;
                if((i>>a[j])&1) 
                    x[j]|=1<<a[j];
                if((i>>(b[j]+5))&1) 
                    x[j]|=1<<(b[j]+5);
                for(k=0; k<j; k++) 
                    if (x[j]==x[k] && (a[j]!=a[k] || b[j]!=b[k])) 
                        break;
                if (k<j) 
                    break;
            }
            if(j>=n) 
                r=min(r,c[i]);
        }
        printf("%d
",r);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/qscqesze/p/4548776.html