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. Java面试集合(四)

    1. jdk,jre,jvm之间的关系 JVM是Java虚拟机,是Java跨平台的重要保障,JVM实现Java跨平台的前提,可以针对不同的操作系统,有不同的JVM. 可以说Java语言是跨平台的,但J ...

  2. [Postman]Postman导航(3)

    Postman提供了一个多窗口和多标签界面,供您使用API​​. 此界面设计为您提供尽可能多的API空间. 侧边栏 邮差侧边栏可让您查找和管理请求和集合.侧边栏有两个主要选项卡:  历史记录  和   ...

  3. 微信小程序 获得用户输入内容

    在微信小程序里,如何获得用户输入的内容?? js: document.getElementById("Content").value jq:$("#Content&quo ...

  4. Vagrant Ansible Playbook 安装一群虚拟机

    https://docs.ansible.com/ https://favoorr.github.io/2017/01/06/vagrant-virtualbox-vagrantfile-config ...

  5. Spring Aop分析

    前言 上文讲述ioc框架的实现,本文开始讲述aop.在spring中aop也有3种配置方式,注解形式的我们先不讨论.我们先看看xml形式的配置方式. <aop:config> <ao ...

  6. 【转载】uCOS2 关于进程调度的O(1)算法

    uCOS2唯一值得学习的一个地方就是关于进程调度的O(1)算法: 最简单也是最愚蠢的方法是维护一个链表List. 这种方法的问题是:当一个Thread就绪时,如果根据其优先级插入List,则算法的时间 ...

  7. C# 通过java生成的RSA公钥加密和解密

    最近工作需要将对方公司生成的RSA加密公钥进行明文加密和解密,发现了几点贴出来做个笔记. RSA单次加密是有长度限制!微软封装的加密方法如果出现长度超出指定范围的话报错是直接报“该项不适于在指定状态下 ...

  8. Canal 源码走读

    前言 canal 是什么? 引用一下官方回答: 阿里巴巴mysql数据库binlog的增量订阅&消费组件 canal 能做什么? 基于日志增量订阅&消费支持的业务: 数据库镜像 数据库 ...

  9. python模块之shutil

    shutil是一个用于简化文件操作的模块. 复制文件(传入源文件对象和目标文件对象) import shutil f1 = open(r'/Users/jingxing/PycharmProjects ...

  10. java当中的强引用,软引用,弱引用,虚引用

    强引用,软引用,弱引用,虚引用:不同的引用类型主要体现在GC上 强引用:如果一个对象具有强引用,它就不会被垃圾回收器回收.即使当前内存空间不足,JVM也不会回收它,而是抛出 OutOfMemoryEr ...