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. Android实现button一边圆角一边直角

    http://www.it165.net/pro/html/201503/36211.html

  2. win7 共享的问题,"您可能没有权限使用网络资源"的解决办法

    重点来了,如果以上方法都不行的话,下面这个绝对有效,本人屡试不爽.1 打开受访者的guest权限2 开始--运行--gpedit.msc3 windows设置---安全设置--本地策略--用户权利指派 ...

  3. 【quick-cocos2d-x】Lua 面向对象(OOP)编程与元表元方法

    版权声明:本文为博主原创文章,转载请注明出处. 面向对象是一种对现实世界理解和抽象的方法,是计算机编程技术发展到一定阶段后的产物. 早期的计算机编程是基于面向过程的方法,通过设计一个算法就可以解决当时 ...

  4. 【LeetCode】28 - Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  5. iOS学习中的一些误区

    周二拿到offer之后,周三确定了去哪家,今天周四.今天是一个例外.中午写更新. 人到了不同的阶段,最重要的就是要更新自己的方法论.也就是说,不能穿新鞋,走老路,这样人就不会有大的突破. 下面我就分析 ...

  6. html5 base64基础

    base64常见的编码形式,二进制文件.图片.视频等     如何弄出来一个base64?     a). FileReader         readAsDataURL();     b). 工具 ...

  7. 第三百三十八天 how can I 坚持

    下午去奥体森林公园跑了个步,好累. 晚上和徐斌同学一起吃了个饭,接触了下杨辉三角,还没整明白,明天看下. 突然想起java 编译,ant脚本. 要精通门技术,还要赶上潮流. 睡觉.

  8. UNITY3D MAC版本破解

    百度网盘下载地址: http://pan.baidu.com/s/1eQmvLqa#path=%252F 包含本体和破解文件 首先说明一下,如果是公司做开发建议去购买正版. 之前网上也有很多人贴出了破 ...

  9. poj 2299 Ultra-QuickSort(求逆序对)

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 52778   Accepted: 19348 ...

  10. HDU 5828 Rikka with Sequence (线段树+剪枝优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,三种操作.操作1是将l到r之间的数都加上x:操作2是将l到r之间的数都开方:操作3是 ...