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[],b[],x[],c[];
char s[];
int main()
{
while(~scanf("%d",&n))
{
for (i=; i<n; i++)
{
scanf("%s",s);
if (s[]=='R')
a[i]=;
if (s[]=='G')
a[i]=;
if (s[]=='B')
a[i]=;
if (s[]=='Y')
a[i]=;
if (s[]=='W')
a[i]=;
b[i]=s[]-'';
}
for (r=, i=; i<(<<); i++)
{
if(i)
c[i]=c[i/]+(i&);
for(j=; j<n; j++)
{
x[j]=;
if((i>>a[j])&)
x[j]|=<<a[j];
if((i>>(b[j]+))&)
x[j]|=<<(b[j]+);
for(k=; 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\n",r);
}
return ;
}

Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力的更多相关文章

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

  2. Codeforces Round 253 (Div. 2)

    layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  3. Codeforces Round #253 (Div. 1) (A, B, C)

    Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然 ...

  4. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

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

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

  6. Codeforces Round #253 (Div. 2) D. Andrey and Problem

    关于证明可以参考题解http://codeforces.com/blog/entry/12739 就是将概率从大到小排序然后,然后从大到小计算概率 #include <iostream> ...

  7. Codeforces Round #253 (Div. 2) D题

    题目大意是选出一个其他不选,问问最大概率: 刚开始想到DP:F[I][J][0]:表示从 前I个中选出J个的最大值, 然后对于F[I][J][1]=MAX(F[I-1][J][1],F[I-1][J- ...

  8. Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat

    本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...

  9. Codeforces Round #253 (Div. 2) A. Anton and Letters

    题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm ...

随机推荐

  1. win7 下配置resin的一些tip

    一.如何查看jdk安装目录: 通过不同方法搜索javac看看, javac.exe 是java的编译器: 可用的搜索方法: 1.cmd 控制台:  where javac 2.开始菜单的搜索: 一直到 ...

  2. jquery禁用右键单击功能屏蔽F5刷新

    1.禁用右键单击功能$(document).ready(function() { $(document).bind("contextmenu",function(e) { aler ...

  3. A.xml

    pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...

  4. bzoj 3594 [Scoi2014]方伯伯的玉米田(DP+二维BIT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3594 [题意] 给定一个n个数的序列,有K次将一个区间内的数加1的机会,问最长不下降子 ...

  5. 关于DIV+CSS和XHTML+CSS的理解

    WEB标准是一系列标准的集合,并不是仅“DIV+CSS”布局就可以实现.以CSS网页布局只是标准的基础之一.“DIV+CSS”布局只是一种通俗的称呼罢了.而我们学习的目标在于以XHTML建立良好的语义 ...

  6. stardict

    1.下载词典文件: 2.把下载到的文件移动到/tmp目录下 # mv stardict-*.bz2 /tmp 3.解压缩 # tar jxf stardict-oxford-gb-2.4.2.tar. ...

  7. Hadoop学习笔记3---安装并运行Hadoop

    本文环境是在Ubuntu10.04环境下运行的. 在Linux上安装Hadoop之前,首先安装两个程序: 1.JDK1.6(或更高版本).Hadoop是用Java编写的程序,Hadoop编译及MapR ...

  8. 在IIS 中如何配置URL Rewrite,并且利用出站规则保持被重写的Cookie的域

    Url Rewrite配置 xx.aa.com/bb/test1.aspx 会重写到 bb.aa.com/test1.aspx 具体怎么配置入站 出站规则 结果:

  9. openstack kilo 流量

  10. 实体框架 (EF) 入门 => 五、连接和模型

    public class BloggingContext : DbContext  {  public BloggingContext()          : base("name=Blo ...