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

时间:2021-02-03 23:47:05

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 &num;253 &lpar;Div&period; 1&rpar; 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 &lpar;Div&period; 2&rpar;

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

  3. Codeforces Round &num;253 &lpar;Div&period; 1&rpar; (A&comma; B&comma; C&rpar;

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

  4. Codeforces Round &num;297 &lpar;Div&period; 2&rpar;D&period; Arthur and Walls 暴力搜索

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

  5. Codeforces Round &num;253 &lpar;Div&period; 2&rpar;——Borya and Hanabi

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

  6. Codeforces Round &num;253 &lpar;Div&period; 2&rpar; D&period; Andrey and Problem

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

  7. Codeforces Round &num;253 &lpar;Div&period; 2&rpar; 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 &num;253 &lpar;Div&period; 2&rpar; B - Kolya and Tandem Repeat

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

  9. Codeforces Round &num;253 &lpar;Div&period; 2&rpar; A&period; Anton and Letters

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

随机推荐

  1. AC日记——最小的N个和 codevs 1245

    1245 最小的N个和  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 有两个长度为 N ...

  2. jQuery遍历多层json数据

    1.json与jsonp的区别(待查) 2.要遍历的数据如下: {"status": "ok", "code": 200, "da ...

  3. HTML特殊字符大全2

    HTML的特殊字符我们并不常用,但是有的时候却要在页面中用到这些字符,甚至有时候还需要用这些字符来实现某种特殊的视觉效果.现在,国外的设计师Neal Chester整理了一份很全的特殊字符集,我觉得这 ...

  4. SSE求解向量大小

    float f=; __asm { mov esi, this ; vector u movups xmm0, [esi] ; first vector in xmm0 mulps xmm0, xmm ...

  5. ajax post传值

    一.字符串             $.ajax({                type: "POST",                data: {"ID&quo ...

  6. js面向对象&plus;一般方法的选项卡

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. JSON 转换异常 multipartRequestHandler servletWrapper

    下面出现红色的字还有警告,解决方法:本人项目是struts1 from类继承了“extends ActionForm” .把它去掉就行了.如果你是其它的框架一定是继承引起的作个参考吧. ....... ...

  8. go学习笔记(一)

  9. Go常用功能总结一阶段

    1. go语言从键盘获取输入内容 <1. 最简单的办法是使用 fmt 包提供的 Scan 和 Sscan 开头的函数.请看以下程序: package main import "fmt& ...

  10. 记一次很坑的python2与python3共存问题

    当添加PYTHONPATH环境变量时,无论输入pip2 -V还是pip3 -V都显示的是python2的环境变量,使用pip3 install 时也是安装在了python2的三方库(因为python2 ...