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

Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力相关推荐

  1. Codeforces Round #743 (Div. 2) E. Paint 区间dp + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一个有nnn个像素的图像,每个像素都有一个颜色aia_iai​,保证每种颜色的图像不会超过202020个.你现在每次可以选择一个颜色,并选择一段连续的像素 ...

  2. Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)

    题目链接:Codeforces Round #271 (Div. 2) C. Captain Marmot 题意:给4行数据,每行2个点.(x,y).(a,b).意思是(x,y)绕(a,b)逆时针旋转 ...

  3. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  4. Codeforces Round #614 (Div. 2) D. Aroma‘s Search 暴力 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你x0,y0,ax,ay,bx,byx_0,y_0,a_x,a_y,b_x,b_yx0​,y0​,ax​,ay​,bx​,by​,让后根据[ax∗xi−1+ ...

  5. Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力

    A. Primes or Palindromes? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=326 ...

  6. Codeforces Round #481 (Div. 3) F. Mentors(排序,暴力,map记忆化)

    题目 题意: 如果一个程序员比另一个程序员的能力值高,而且这两个程序员不在争吵状态,则能力值较高的程序员可以成为另一个程序员的老师,求每个程序员能成为多少其他程序员的老师. 思路: 先啥都不管,结构体 ...

  7. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  8. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  9. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

最新文章

  1. 中国工业机器视觉产业发展白皮书(附ppt)
  2. python post请求 415_接收错误415:使用REST API发送GET请求时不支持媒体类型
  3. 两数之和 python_同一屏幕播放两个视频 视频左右两个画面或视频上下两个画面如何制作...
  4. css3动画事件—webkitAnimationEnd
  5. 《JavaScript DOM编程艺术》笔记
  6. python输出用逗号隔开的数字_Python:从字符串中提取带有点和逗号的数字
  7. codevs 5958 无
  8. gb28181的sip通信
  9. 自动驾驶传感器---毫米波雷达原理(测距、测速、角速度测量),毫米波雷达系统构成
  10. 恭贺除夕,没什么才艺展示,就给大家画新年四格小漫画吧 >⌒<
  11. Spark on Hive Hive on Spark,傻傻分不清楚
  12. backdrop-filter高斯模糊
  13. 腾讯坐标系转化成百度坐标系
  14. 快排及时间复杂度简单证明
  15. 5月14日国内主流平台数字藏品发售日报
  16. 数说IN语丨万豪酒店再敲警钟!防数据泄露,数博士有妙招!
  17. 【前端知识点】promise简书-30分钟带你搞懂promise面试必备
  18. 行业云服务——乐视云点播服务试用体验
  19. webpack坑系列--安装webpack-cli
  20. 从零开始研发GPS接收机连载——7、跟踪模块概述和设计

热门文章

  1. 新概念英语第一册1-34课单词
  2. SQLyog中TAB键设置四个空格的步骤
  3. [POJ1741]Tree
  4. 原生JS实现$.ajax
  5. 消息模式Toast.makeText的几种常见用法
  6. 古怪的ConfigurationManager
  7. BCH表现良好,BTC调整蓄势
  8. 以佛像喷泉来探讨BCH物联网应用潜力
  9. 10秒完成Linux系统pip在线安装
  10. 如何在 Shell 脚本中执行语法检查调试模式