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的更多相关文章
随机推荐
- MSMQ队列的简单使用
微软消息队列-MicroSoft Message Queue(MSMQ) 使用感受:简单. 一.windows安装MSMQ服务 控制面板->控制面板->所有控制面板项->程序和功能- ...
- 微博第三方登录使用social_django实现显示登陆的用户名
首先修改social_soce源码,将用户信息添加进cookie 将其修改为: response = backend.strategy.redirect(url) payload = jwt ...
- Kali学习笔记31:目录遍历漏洞、文件包含漏洞
文章的格式也许不是很好看,也没有什么合理的顺序 完全是想到什么写一些什么,但各个方面都涵盖到了 能耐下心看的朋友欢迎一起学习,大牛和杠精们请绕道 目录遍历漏洞: 应用程序如果有操作文件的功能,限制不严 ...
- jupyter notebook的安装与基本操作
0.前言 最近正在重温Python基础知识,为了方便练习敲代码,于是选择安装jupyter notebook作为代码编辑器. Project Jupyter exists to develop ope ...
- Python 22端口发邮件
#!/usr/bin/python#-*-coding:UTF-8-*- import smtplibimport timeimport os from email.mime.text import ...
- 分布式作业 Elastic Job 如何动态调整?
前面分享了两篇分布式作业调度框架 Elastic Job 的介绍及应用实战. ElasticJob-分布式作业调度神器 分布式作业 Elastic Job 快速上手指南! Elastic Job 提供 ...
- pytorch bug: for step,data in enumerate(loader)+Connection reset by peer
单GPU跑的程序,而且是在docker中,迭代了几百步后,程序突然崩掉了, 程序停在了 for step,data in enumerate(loader),下面是部分bug信息 Traceback ...
- Git基本命令 -- 基本工作流程 + 文件相关操作
可以先找一个已经被git管理的项目, 我就使用这个项目吧: https://github.com/solenovex/ID3-Editor 基本工作流程 克隆以后呢, 进入该目录查看一下状态: 然后添 ...
- 一个系统部署多个tomcat实例
一.添加环境到/etc/profile. JAVA_HOME=/usr/java/jdk1.8.0_111 PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HO ...
- IdentityServer(13)- 使用 JavaScript 客户端
本文使用的授权码模式,已更新至 .NET Core 2.2 本快速入门将展示如何构建基于浏览器的 JavaScript 客户端应用程序(SPA). 用户将登录 IdentityServer,使用 Id ...