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/problem/A
Description
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
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[],b[],x[],c[];
char s[];
int main()
{
while(~scanf("%d",&n))
{
for (i=; i<n; i++)
{
scanf("%s",s);
if (s[]=='R')
a[i]=;
if (s[]=='G')
a[i]=;
if (s[]=='B')
a[i]=;
if (s[]=='Y')
a[i]=;
if (s[]=='W')
a[i]=;
b[i]=s[]-'';
}
for (r=, i=; i<(<<); i++)
{
if(i)
c[i]=c[i/]+(i&);
for(j=; j<n; j++)
{
x[j]=;
if((i>>a[j])&)
x[j]|=<<a[j];
if((i>>(b[j]+))&)
x[j]|=<<(b[j]+);
for(k=; 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 ;
}
Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力的更多相关文章
- 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 Round 253 (Div. 2)
layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #253 (Div. 1) (A, B, C)
Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然 ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #253 (Div. 2)——Borya and Hanabi
题目连接 题意: n表示有n个卡片.每一个卡片有一种颜色和一个数字(共五种不同的颜色和五个不同的数字). 事先知道每种卡片有几张.可是不知道详细的位置. 问须要几次提示就能够知道全部卡片的位置都在哪里 ...
- Codeforces Round #253 (Div. 2) D. Andrey and Problem
关于证明可以参考题解http://codeforces.com/blog/entry/12739 就是将概率从大到小排序然后,然后从大到小计算概率 #include <iostream> ...
- Codeforces Round #253 (Div. 2) D题
题目大意是选出一个其他不选,问问最大概率: 刚开始想到DP:F[I][J][0]:表示从 前I个中选出J个的最大值, 然后对于F[I][J][1]=MAX(F[I-1][J][1],F[I-1][J- ...
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...
- Codeforces Round #253 (Div. 2) A. Anton and Letters
题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm ...
随机推荐
- 解决oracle11g的ORA-12505问题
今天在使用SQL Developer的时候连不上去,报ORA-12505错误,但是SQLPLUS可以连接. 检查服务名,是OracleServiceORCL,那SID应当就是orcl,但是使用该SID ...
- 使用Junit实现批量运行
我们知道使用testng可以很方便的实现批量运行,但有的同学更习惯用junit,那么junit是否也有批量运行的功能呢?答案是 YES,而且有2种方法: 第一种, 选择要测试的包(注意是包而不是文件) ...
- <转>selenium+python+API分类总结
分类 方法 方法描述 客户端操作 __init__(self, host, port, browserStartCommand, browserURL) 构造函数.host:selenium serv ...
- Java核心_内省
Java核心_内省 查看java的api,发现有一个包java.bean咦,这个包是干什么的呢,原来,它是用来操作JavaBean对象的! 一.内省操作①JavaBean:一种特殊的Java类无参构造 ...
- 设计模式 外观 Facade
外观模式的作用是简化接口.它提供一个统一的接口用来访问子系统的一群接口.通过这个高层接口使子系统更容易使用. 同时,通过外观将客户从组件的子系统中解耦. Head 1st中使用了家庭影院的例子来说明外 ...
- 常用SQL整理
整理了日常用到的一些sqls 1.插入表 insert into table_B select * from table_A 2.清空表 truncate table test #清空表,结构还存在d ...
- 一起刷LeetCode5-Longest Palindromic Substring
发现自己原来掌握的一下算法,都忘掉了,啊啊啊 ----------------------------------------------------------------------------- ...
- 【boost】使用装饰者模式改造boost::thread_group
在项目中使用boost::thread_group的时候遇到几个问题: 1.thread_group不提供删除全部thread列表的方法,一直使用create会是其内部列表不断增加. 2.thread ...
- .net调用java webservice基于JBOSS服务器 学习笔记(一)
1.遇到数组类型或List等复杂数据类型是,需要对其进行包装,就是将复杂数据类型放到一个类里面: public class VOCargoJTWS { /** JT列表 */ private List ...
- HashSet与HashMap、Hashtable
(最近在老师叫我们用java去实现LRU算法,了解到要用双链表去做,要用到LinkHashMap去做,但自己对java的几大集合框架并不熟悉,在学习过程了解到了HashMap和HashSet,做个简单 ...