Codeforces 442A
A. Borya and Hanabitime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
InputThe 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.
OutputPrint a single integer — the minimum number of hints that the other players should make.
Sample test(s)input2
G3 G3output0input4
G4 R4 R3 B3output2input5
B1 Y1 W1 G1 R1output4NoteIn 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.
Accepted Code:
from collections import defaultdict def main():
input()
cards = list(set(raw_input().split())); if len(cards) == 1:
print 0
return
answer = 9;
chars = 'RGBYW12345'
for mask in xrange(1, 1024):
cover = ''
for i in xrange(10):
if (mask & (1<<i)):
cover += chars[i] d = defaultdict(int) for card in cards:
if card[0] in cover and card[1] in cover:
continue;
if card[0] in cover:
d[card[0]] += 1;
elif card[1] in cover:
d[card[1]] += 1;
else:
d['*'] += 1; if all(x <= 1 for x in d.values()):
answer = min(answer, len(cover)); print answer; if __name__ == '__main__':
main()
第一次使用collections.defaultdict,如果定义一个dict(字典),当访问一个不存在的键值的时候会发生异常,
但是defaultdict这种情况下就会提供一个默认值,他使用一个函数作为初始化的参数,可以是内建的类型,如int, list等,
还可以是用户自定义的不含参数的函数,以该函数的返回值作为其默认值。
关于all这个函数,他以一个可迭代的类型的对象作为参数,当所有的值都为True则返回True
Codeforces 442A的更多相关文章
- Codeforces 442A Borya and Hanabi
有五种花色 外加 五种点数 共25张牌,每次有n张牌,主人知道这n张牌中有哪些牌,并且哪种牌有几张,但是不知道具体是哪张牌,他可以问某种花色,然后知道了哪几张是该花色,也可以问点数,然后就知道了哪几张 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 二进制操作(1)–Bytes
1,Bytes的单元被当作字符串处理. 例如: 有些介绍会声称上述程序会得到这样的结果:b'\x00\x00\x00\x00' 在python v2.7.10上是得不到此结果的. 实际上,如果 typ ...
- 基于PtrFrameLayout实现自定义仿京东下拉刷新控件
前言 最近基于项目需要,使用PtrFrameLayout框架实现了自定义的下拉刷新控件,大体效果类似于京东APP的下拉刷新动态效果.在这里和大家分享一下具体的思路和需要注意的地方,以便帮助有类似开发和 ...
- 处理iphone的 .play() 不能播放问题
一.添加音乐 <audio id="Jaudio" src="shake.mp3" preload loop="loop" contr ...
- JDK、Eclipse、Tomcat、Maven、IDEA 常见问题
windows操作分成了32位和64位的系统,不同的系统安装的软件也不一样. 查询电脑操作系统是多少位? J D K 01. 下载安装 02. 目录解释 03. 配置环境变量 (JDK安装成功后进行配 ...
- redis学习笔记05-发布订阅模式
由于redis消息队列并不支持多播机制,即生产者产出一次,由中间件复制发送给多个消费者的机制,为了弥补这个不足,单独引入了发布订阅模式的模块.使用方式如下: #生产者 import redis cli ...
- 提高scrapy的抓取效率
增加并发 默认scrapy开启的并发线程的个数是32个,可以适当的进行增加.在settings中进行设置CONCURRENT_REQUESTS=100 降低日志级别 在运行的时候,会有大量的日志信息的 ...
- 跟我一起做一个vue的小项目(十一)
接下来我们进行的是详情页动态路由及banner布局 先看页面的效果 下面是代码部分 <template> <div> <div class="banner&qu ...
- angular7.X配置同时使用localhost和本机IP访问项目
1.项目中找到此文件“node_modules/webpack-dev-server/lib/Server.js”,按照下图修改: 二.修改配置文件package.json,见下图: 三.npm st ...
- .NET2.0引用.NET3.5的System.Core.dll&Dapper在.NET2.0下的配置
微软MSDN对.NET2.0,3.0,3.5的描述: .NET Framework 版本 2.0.3.0 和 3.5 是使用同一 CLR 版本 (CLR 2.0) 生成的. 这些版本表示单个安装的连续 ...
- springboot之jpa(简述)
1.maven引入jar包(jpa和mysql) <dependency> <groupId>org.springframework.boot</groupId> ...