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. mysql5.5 五种日期

    mysql(5.5)所支持的日期时间类型有:DATETIME. TIMESTAMP.DATE.TIME.YEAR. 几种类型比较如下: 日期时间类型 占用空间 日期格式 最小值 最大值 零值表示  D ...

  2. 9.代码抽取(adapter)

    1  抽取Adapter 共性的方法 2  把getView方法里 和holder相关的逻辑 摘取到Holder代码中 3  把Holder 相关的代码 抽取到BaseHolder中  4  把ada ...

  3. 110道python面试笔试题汇总,你能答对几道?

    数据分析系列教程插播一篇面试题教程,最近公众号新来了不少朋友,这几天不少粉丝留言说问我有没有python面试题,其实之前分享过一些面试题,今天统一再给大家分享一遍,也希望能帮助此时仍在找工作的同学,尽 ...

  4. [Postman]响应(7)

    Postman响应查看器有助于确保API响应的正确性.API响应由正文,标题和状态代码组成.邮递员在不同的标签中组织正文和标题.选项卡旁边会显示API调用的状态代码和完成时间. 响应还包含HTTP规范 ...

  5. python 利用matplotlib中imshow()函数绘图

    matplotlib 是python最著名的2D绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中.通过简单的绘图语 ...

  6. FAIR开源Detectron:整合全部顶尖目标检测算法

    昨天,Facebook AI 研究院(FAIR)开源了 Detectron,业内最佳水平的目标检测平台. 昨天,Facebook AI 研究院(FAIR)开源了 Detectron,业内最佳水平的目标 ...

  7. linux查看系统32位还是64位

    1. 从系统查看 1.1 uname -a 命令 [root@qs-dmm-rh2 ~]# uname -a Linux qs-dmm-rh2 2.6.18-194.el5 #1 SMP Tue Ma ...

  8. 使用 dotTrace 分析 .NET Core 代码问题

    0.背景 在项目开发之中,前期可能主要以保证任务完成为主,对于性能优化主要在于开发完成之后再来进行.可能在测试的时候发现部分接口的代码执行时间过长,但是又毫无头绪,这个时候你就需要性能分析工具来协助你 ...

  9. Java核心技术及面试指南 线性表方面的面试题总结以及答案

    3.2.7.1 请用ArrayList实现Stack以及Queue的功能. public class ArrayListStack extends ArrayList implements Stack ...

  10. 小程序开发--template模板

    小程序的template模板可以说是我遇到的最简单的了,看看实例: <template name="article"> <view class='containe ...