题目链接:

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

题意:

现在知道有哪些牌,但不知具体顺序,每次询问都会知道这个询问的相关的牌的位置,问最少需要多少次询问;

思路:

变成二维的点,划线后被两次覆盖的点可以删去,剩下的一行或者一列只有一个的也可以删去了;
看最后如果剩下的个数<=1就这种选择就可行; AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=5e5+10; int n,a[6][6],x[6],y[6],b[6][6],numx[6],numy[6];
char s[2];
int check(int temp)
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
b[i][j]=a[i][j];
for(int i=0;i<5;i++)if((temp>>i)&1)x[i]=1;else x[i]=0;
for(int i=5;i<10;i++)if((temp>>i)&1)y[i-5]=1;else y[i-5]=0;
for(int i=0;i<5;i++)
{
if(x[i])
{
int num=0;
for(int j=0;j<5;j++)if(b[i][j])num++;
if(num==1)
{
for(int j=0;j<5;j++)b[i][j]=0;
}
}
}
for(int i=0;i<5;i++)
{
if(y[i])
{
for(int j=0;j<5;j++)
{
if(b[j][i]&&x[j])b[j][i]=0;
}
int num=0;
for(int j=0;j<5;j++)if(b[j][i])num++;
if(num==1)
{
for(int j=0;j<5;j++)b[j][i]=0;
}
}
}
for(int i=0;i<5;i++)
{
if(x[i])
{
int num=0;
for(int j=0;j<5;j++)if(b[i][j])num++;
if(num==1)
{
for(int j=0;j<5;j++)b[i][j]=0;
}
}
}
int num=0;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
if(b[i][j])num++;
if(num>1)return 10;
int ans=0;//cout<<temp<<"*****"<<endl;
while(temp){if(temp&1)ans++;temp>>=1;} return ans;
}
int main()
{
scanf("%d",&n);
int fx,fy;
for(int i=1;i<=n;i++)
{
scanf("%s",s);
if(s[0]=='R')fx=0;
else if(s[0]=='B')fx=1;
else if(s[0]=='Y')fx=2;
else if(s[0]=='W')fx=3;
else fx=4;
fy=s[1]-'0'-1;
a[fx][fy]++;
}
int num=0;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
if(a[i][j])num++;
if(num<=1){printf("0\n");return 0;}
int ans=10;
for(int i=0;i<(1<<10);i++)ans=min(ans,check(i));
cout<<ans<<endl;
return 0;
}

  

codeforces 422A A. Borya and Hanabi(暴力)的更多相关文章

  1. 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/p ...

  2. [CF442A] Borya and Hanabi (暴力bitmask)

    题目链接:http://codeforces.com/problemset/problem/442/A 题目大意:给你n张卡片,你知道这n张卡片都是什么,但是不知道他们的位置.你每次可以请求朋友指出一 ...

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

    A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #253 (Div. 2)——Borya and Hanabi

    题目连接 题意: n表示有n个卡片.每一个卡片有一种颜色和一个数字(共五种不同的颜色和五个不同的数字). 事先知道每种卡片有几张.可是不知道详细的位置. 问须要几次提示就能够知道全部卡片的位置都在哪里 ...

  5. Codeforces 442A Borya and Hanabi

    有五种花色 外加 五种点数 共25张牌,每次有n张牌,主人知道这n张牌中有哪些牌,并且哪种牌有几张,但是不知道具体是哪张牌,他可以问某种花色,然后知道了哪几张是该花色,也可以问点数,然后就知道了哪几张 ...

  6. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  7. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  8. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  9. Codeforces 839A Arya and Bran【暴力】

    A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...

随机推荐

  1. android MVP模式介绍与实战

    android MVP模式介绍与实战 描述 MVP模式是什么?MVP 是从经典的模式MVC演变而来,它们的基本思想有相通的地方:Controller/Presenter负责逻辑的处理,Model提供数 ...

  2. 桂电在linux、Mac OS环境下使用出校器(支持2.14)

    这是guetsec学长在三院科协学长所抓包逆向分析1.81版出校器的基础上,用python写的一款为Mac和linux环境开发的出校器. 最后我做了略微修改,支持暂时最新版本2.14.下面有直接从源码 ...

  3. (八)play之yabe项目【身份验证】

    (八)play之yabe项目[身份验证] 博客分类: 框架@play framework   添加身份验证 play提供了一个模块-Secure(安全模块),用来做身份验证 允许Secure模块 修改 ...

  4. 使用openssl创建自签名证书及部署到IIS教程

    概要 本文讲解三个部分:1. 创建自签名证书2. 创建自己的证书颁发机构3. 以及如何配置IIS 创建自签名证书 首先,创建一个私钥文件: openssl genrsa -out myselfsign ...

  5. 使用HyperV虚拟机装系统

    新建虚拟机 新建虚拟机 进行相关参数设置 选择系统安装镜像位置,名称及位置 指定代数一般为1代即可 为虚拟机运行分配内存 创建虚拟硬盘或连接已有虚拟硬盘,并分配硬盘空间 核对创建虚拟机相关信息 安装系 ...

  6. 关于在EXCEL中输入01-01-01被转换为2001/1/1怎么解决

    当向EXCEL写入类似'01-01-01'或'01-01'这样的数据时,打开EXCEL时会发现数据变成了2001/1/1和1月1日. 这是由于EXCEL自动转换功能,我们得要在输入前多加一个’号. 而 ...

  7. 通过SMATFORMS打印程序的参考模板

    REPORT  ydemo_rick_print. CONSTANTS: c_lable_smartforms TYPE tdsfname VALUE 'ZCUSTOMER'. "标签sma ...

  8. MySQL数据库中字符集的问题

    今天在做Hibernate案例,往mysql中写记录的时候,出现ERROR: Incorrect string value: '\xE5\x8A\xA0\xE5\x86\x85...' for col ...

  9. Android--Apache HttpClient

    前言 上一篇文章介绍了使用HttpURLConnection来完成对于HTTP协议的支持.现在介绍一个新的方式来访问Web站点,那就是HttpClient. HttpClient是Apache开源组织 ...

  10. iOS 简单工厂模式

    iOS 简单工厂模式 什么是简单工厂模式? 简单工厂模式中定义一个抽象类,抽象类中声明公共的特征及属性,抽象子类继承自抽象类,去实现具体的操作.工厂类根据外界需求,在工厂类中创建对应的抽象子类实例并传 ...