Codeforces442A
A. Borya and Hanabi
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
Note
In the first sample Borya already knows for each card that it is a green three.
In the second sample we can show all fours and all red cards.
In the third sample you need to make hints about any four colors.
题意
有一个人知道有哪些牌,但是不知道这些牌是哪张。
他每次可以问2个问题,
1.x颜色的牌是哪些
2.数值为y的牌是哪些
然后问最少多少次询问,这个人才能分清哪些牌是哪些
思路:
我们把这些牌抽象成二维空间的点,然后我们开始画线
如果这个平面上的点少于等于1个,那么我们就可以说明这个人已经分清了
那么哪些点我们可以删去呢?只要这个点被两条线段覆盖,或者这条线段上只有这么一个点,那么这个点就是可以被删除的
观察到一共有五种颜色,有五种数字,那么其实我们最多猜10次就一定能够得到结果了。
那么考虑2^10枚举所有操作情况,那么对应暴力处理,判断结果是否可行,维护最小即可。
//2018-08-12
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int x[N], y[N], info[N], n; int color_to_id(char ch){
if(ch == 'R')return ;
if(ch == 'G')return ;
if(ch == 'B')return ;
if(ch == 'Y')return ;
if(ch == 'W')return ;
} int count_one(int x){
int cnt = ;
while(x){
cnt += (x&);
x >>= ;
}
return cnt;
} bool check(int sta){
for(int i = ; i < n; i++){
info[i] = ;
info[i] |= (<<(x[i]-))&sta;
info[i] |= (<<(y[i]-+))&sta;
for(int j = ; j < i; j++)
if(info[i] == info[j] && (x[i]!=x[j] || y[i]!=y[j]))
return false;
}
return true;
} int main()
{
string str;
while(cin>>n){
for(int i = ; i < n; i++){
cin>>str;
x[i] = color_to_id(str[]);
y[i] = str[]-'';
}
int ans = ;
for(int i = ; i < (<<); i++){
int n_one = count_one(i);
if(n_one >= ans)continue;
if(check(i))ans = n_one;
}
cout<<ans<<endl;
} return ;
}
Codeforces442A的更多相关文章
随机推荐
- Python编程练习:编程实现恺撒密码
问题描述:凯撒密码是古罗马凯撒大帝用来对军事情报进行加解密的算法,它采用了替换方法对信息中的每一个英文字符循环替换为字母表序列中该字符后面的第三个字符,即,字母表的对应关系如下: 原文:A B C D ...
- 每天学点SpringCloud(十一):Hystrix仪表盘
在SpringCloud学习系列博客第六篇文章中,我们已经学习了Hystrix的使用,但是那篇文章中有一点遗漏没有讲,那就是Hystrix Dashboard ,它可以实时的监控Hystrix的运行情 ...
- Go语言生成随机数
在Go语言中生成随机数需要使用Seed(value)函数来提供伪随机数生成种子,一般情况下都会使用当前时间的纳秒数字,如果不在生成随机数之前调用该函数,那么每次生成的随机数都是一样的. 函数rand. ...
- Python开发端口扫描器
首先是最常用的端口扫描器: 虽说有nmap等强大的工具,不过如果由于条件限制无法安装Nmap呢? 我这个脚本写的比较简单,默认扫描1-65535全部的端口 实际的话,可以根据需要自己修改脚本来实现定制 ...
- 读《Linux Shell脚本攻略》(第2版) 一遍、二遍体会
前段时间读完了<Linux Shell脚本攻略>(第2版)这本书,给部分想读这本书的人分享下个人感受. 第一遍体会解读:就像黑夜中的灯塔,指明前进的道路. 推荐指数:强烈推荐. 书中讲解的 ...
- 传参导出Excel表乱码问题解决方法
业务场景 先描述一下业务场景,要实现的功能是通过搜索框填写参数,然后点击按钮搜索数据,将搜索框的查询参数获取,附加在链接后面,调导Excel表接口,然后实现导出Excel功能.其实做导Excel表功能 ...
- Kubernetes 新时代的宠儿
本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. Kuberne ...
- odoo开发笔记 -- many2one搜索更多增加默认过滤条件
没加过滤条件的时候,效果如下,点击下拉框,搜索更多出现所有模型下的模板: 改进方法(增加默认过滤条件,显示指定模型下的内容): class IrCloudReport(models.Model): _ ...
- mysql 开发进阶篇系列 52 权限与安全(系统四个权限表的粒度控制关系)
一.概述 接着上篇的权限介绍,当用户进行连接的时候,权限表的存取过程有以下两个阶段: (1) 先从user表中的host,user, authentication_string 这3个字段中判断连接的 ...
- IT十年经典书籍
摘自网络,近来在浏览时,发现一个叫做“IT十年经典书籍”的主题.google了一下,实在找不出这个主题的源头出处.不过这个主题中所涉及的每一本书讲出来都是振聋发聩的,大可以作为它那个行业的经典了. ...