Codeforces 442A Borya and Hanabi
有五种花色 外加 五种点数 共25张牌,每次有n张牌,主人知道这n张牌中有哪些牌,并且哪种牌有几张,但是不知道具体是哪张牌,他可以问某种花色,然后知道了哪几张是该花色,也可以问点数,然后就知道了哪几张是这个点数。最终可以把所有牌都确定下来,问最少要询问几次。
这个题目一开始想到枚举(事实证明最后就是枚举),然后又想到二分图去了,。。主要是这个花色对应点数,连成边之后太像二分图了,而且感觉为了得到所有的牌,隐隐约约有点像 DAG上的最小点覆盖。。。而且看了下样例,有点像,所以就去敲二分图去了,结果。。。擦。跪了
其实还是要回到枚举上面来,总共才10个点是不是,用个状态压缩才1000,关键是怎么判断当前枚举是合法的,正向考虑会比较复杂,我想了半天没想到一个比较轻松的方法,但是反向考虑就舒服多了,假设我枚举了k个点,也就是说这k个点(包括花色与点数)都是要询问的,那么不成立的条件有这样:
1.某种牌的两个端点都没询问,而且不止一次(如果只是一次的话,是可以的,因为主人知道所有的牌,这张牌放到最后即可)。
2.某种牌只访问了一个端点,但是这个端点又不止被访问一次(这样的话就肯定无法确定是哪张牌)
所以只要出现了以上两种情况中的一种,即不合法。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- int mat[][];
- char ch[]={'A','R','G','Y','W','B'};
- int bitcount(int x)
- {
- if (x==) return ;
- else return bitcount(x>>)+(x&);
- }
- bool judge(int x)
- {
- int num[];
- memset(num,,sizeof num);
- int tot=;
- for (int i=;i<=;i++)
- {
- for (int j=;j<=;j++){
- if (mat[i][j]){
- if (((<<(i-))&x) && (!((<<(j-))&x))) num[i]++;
- if ((!((<<(i-))&x)) && ((<<(j-))&x)) num[j]++;
- if ((!((<<(i-))&x)) && (!((<<(j-))&x))) tot++;
- }
- }
- }
- //cout<<tot<<endl;
- if (tot>) return ;
- for (int i=;i<=;i++){
- if (num[i]>) return ;
- }
- return ;
- }
- int main()
- {
- int n;
- char s[];
- while (scanf("%d",&n)!=EOF)
- {
- memset(mat,,sizeof mat);
- for (int i=;i<n;i++){
- scanf("%s",s);
- int a=;
- for (int i=;i<=;i++){
- if (s[]==ch[i]){a=i;break;}
- }
- int b=s[]-''+;
- mat[a][b]=;
- // cout<<a<<" "<<b<<endl;
- }
- int ans=;
- for (int i=;i<(<<);i++){
- if (judge(i)){
- ans=min(ans,bitcount(i));
- }
- //cout<<ans<<endl;
- //if (ans==0) break;
- }
- printf("%d\n",ans);
- }
- return ;
- }
Codeforces 442A Borya and Hanabi的更多相关文章
- Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力
A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/p ...
- codeforces 422A A. Borya and Hanabi(暴力)
题目链接: A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #253 (Div. 1) A Borya and Hanabi
A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 442A
题目链接 A. Borya and Hanabi time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #253 (Div. 2)——Borya and Hanabi
题目连接 题意: n表示有n个卡片.每一个卡片有一种颜色和一个数字(共五种不同的颜色和五个不同的数字). 事先知道每种卡片有几张.可是不知道详细的位置. 问须要几次提示就能够知道全部卡片的位置都在哪里 ...
- [CF442A] Borya and Hanabi (暴力bitmask)
题目链接:http://codeforces.com/problemset/problem/442/A 题目大意:给你n张卡片,你知道这n张卡片都是什么,但是不知道他们的位置.你每次可以请求朋友指出一 ...
- Codeforces Round 253 (Div. 2)
layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces442A
A. Borya and Hanabi time limit per test:2 seconds memory limit per test: 256 megabytes input:standar ...
- 【Codeforces Round #443 (Div. 2) A】Borya's Diagnosis
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] #include <bits/stdc++.h> using namespace std; const ...
随机推荐
- python编写banner获取的常用模块
模块的概念:模块也叫库,每个模块中都内置了大量的功能和函数.类和变量.它就像是积木,可以根据需要进行调用组合.模块就是程序,每个模块就是一个后缀为.py的Python程序.Python的模块分为标准模 ...
- 蓝桥杯 2n皇后问题
题意: 问题描述 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行.同一列或同一条对角线上,任意的两个白皇后都不在同一行.同一 ...
- 17. Getting to the essence of things
17.Getting to the essence of things.抓住事情的本质 From today on, I think I should keep a diary. To the CCU ...
- python笔记10
今日内容 参数 作用域 函数嵌套 知识点回顾 函数基本结果 def func(name,age,email): # 函数体(保持缩进一致) a = 123 print(a) return 1111#函 ...
- 058、Java中定义一个没有参数没有返回值的方法
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- Most simple basic of internet programming based on two different machines sharing the same local net
This blog is just shown for the most simple basic of internet programming based on two different mac ...
- ACM-生化武器
Description在一个封闭的房间里,gogo给大家表演了他的屁遁术,人果然一下没影了,但是他留下的“生化武器”,却以每秒1米的速度向上下左右扩散出去.为了知道自己会不会被“毒”到,你果断写了个算 ...
- NO11 SSH故障排查思路和netstat命令
本章知识相关考试:1.企业场景面试题:Linux系统如何优化?2.企业场景面试题:SSH服务连不上,如何排查?记住回答技巧: 1 ping 2 telnet 客户端ssh工具:SecureCRT,x ...
- Day 26:Dom4j修改xml
Dom4j:Writing a document to a file import java.io.File; import java.io.FileOutputStream; import org. ...
- linux下编译bochs-2.6.2
操作系统: Fedora19 内核: 3.12.9 Linux localhost.localdomain 3.12.9-201.fc19.i686 #1 SMP Wed Jan 29 16:02:1 ...