A. Borya and Hanabi

time limit per test:2 seconds
memory limit per test: 256 megabytes
input:standard input
output:standard output

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.

Examples

input

2
G3 G3

output

0

input

4
G4 R4 R3 B3

output

2

input

5
B1 Y1 W1 G1 R1

output

4

Note

In the first sample Borya already knows for each card that it is a green three.

In the second sample we can show all fours and all red cards.

In the third sample you need to make hints about any four colors.

题意

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

他每次可以问2个问题,

1.x颜色的牌是哪些

2.数值为y的牌是哪些

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

思路:

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

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

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

观察到一共有五种颜色,有五种数字,那么其实我们最多猜10次就一定能够得到结果了。

那么考虑2^10枚举所有操作情况,那么对应暴力处理,判断结果是否可行,维护最小即可。

 //2018-08-12
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int x[N], y[N], info[N], n; int color_to_id(char ch){
if(ch == 'R')return ;
if(ch == 'G')return ;
if(ch == 'B')return ;
if(ch == 'Y')return ;
if(ch == 'W')return ;
} int count_one(int x){
int cnt = ;
while(x){
cnt += (x&);
x >>= ;
}
return cnt;
} bool check(int sta){
for(int i = ; i < n; i++){
info[i] = ;
info[i] |= (<<(x[i]-))&sta;
info[i] |= (<<(y[i]-+))&sta;
for(int j = ; j < i; j++)
if(info[i] == info[j] && (x[i]!=x[j] || y[i]!=y[j]))
return false;
}
return true;
} int main()
{
string str;
while(cin>>n){
for(int i = ; i < n; i++){
cin>>str;
x[i] = color_to_id(str[]);
y[i] = str[]-'';
}
int ans = ;
for(int i = ; i < (<<); i++){
int n_one = count_one(i);
if(n_one >= ans)continue;
if(check(i))ans = n_one;
}
cout<<ans<<endl;
} return ;
}

Codeforces442A的更多相关文章

随机推荐

  1. Python selenium webdriver设置加载页面超时

    1.  pageLoadTimeout: pageLoadTimeout方法用来设置页面完全加载的超时时间,完全加载即页面全部渲染,异步同步脚本都执行完成.没有设置超时时间默认是等待页面全部加载完成才 ...

  2. 吴恩达机器学习笔记37-学习曲线(Learning Curves)

    学习曲线就是一种很好的工具,我经常使用学习曲线来判断某一个学习算法是否处于偏差.方差问题.学习曲线是学习算法的一个很好的合理检验(sanity check).学习曲线是将训练集误差和交叉验证集误差作为 ...

  3. Python学习笔记【第九篇】:Python面向对象基础

    Python语言中一切皆对象(类.属性.方法.........) 概念 面向对象编程:Object Oriented Programming 简称OOP 面向对象程序设计 面向对象和面向过程都是解决问 ...

  4. pycharm注册码(不断更新)

    2019.3.13测试可用 MTW881U3Z5-eyJsaWNlbnNlSWQiOiJNVFc4ODFVM1o1IiwibGljZW5zZWVOYW1lIjoiTnNzIEltIiwiYXNzaWd ...

  5. Python 音视频方面资源大全

    自然语言处理 用来处理人类语言的库. NLTK:一个先进的平台,用以构建处理人类语言数据的 Python 程序.官网 jieba:中文分词工具.官网 langid.py:独立的语言识别系统.官网 Pa ...

  6. vmdk多文件合成单文件并导入

    如果创建时,目录中有多个vmdk文件,可以将其合成一个,方便导到其他地方运行,如图所示 win下cmd命令,找到安装vmware目录,合并的命令如下 vmware-vdiskmanager.exe - ...

  7. SQL三表左关联查询

    今天在开发的时候遇到了一个需求就是三遍关联查询,表A包含有表B和表C的uid,然后使用left join左关联查询: SELECT c.`uid`, `fromuseruid`, `touseruid ...

  8. javaScript笔记详解(1)

    javaScript基础详解 版权声明 本文原创作者:雨点的名字 作者博客地址:https://home.cnblogs.com/u/qdhxhz/ 首先讲javaScript的摆放位置:<sc ...

  9. 【jQuery】(2)---Jquery过滤选择器

                         1.基础选择器: 名称 说明 举例 #id 根据元素Id选择 $("divId") 选择ID为divId的元素 element 根据元素的 ...

  10. 模板发送java邮件

    Creating email content using a templating library The code in the previous examples explicitly creat ...