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 ...
随机推荐
- 平庸与卓越的差别 z
本文是清华大学陈吉宁校长于在 2015 年第一次研究生毕业典礼暨学位授予仪式上的讲话,原文标题:选择与坚持.演讲非常精彩,值得您细细阅读. 亲爱的同学们: 今天,共有 1318 名同学获得博士.硕士学 ...
- Pitcher Rotation
题意: n个人m个对手给出每个人能战胜每个敌人的概率,现在有g个比赛,每个人赛完后要休息4天(可重复用),求能获得胜利的最大期望个数. 分析: 因为只有每个人5天就能用一次,所以对于每个人来说,只有得 ...
- svn import 向Google code里导入初始代码
其实很简单的问题,花费了这么多时间,想把初始代码导入到Google code里,用VisaulSVN插件的Switch功能也不可以,Google code上虽然有上传,但是只能单个文件传...... ...
- 重新开始吧(ADB+AndroidManifest.xml)
我现在默认已经搭建好了开发环境.如果没有,可以参见去Google一下,或者我上两篇文章中也有提到. 先补充一点: SDK不用FQ.也能更新 修改hosts文件 下载sdk版本: 在hosts文件中追加 ...
- pick定理:面积=内部整数点数+边上整数点数/2-1
//pick定理:面积=内部整数点数+边上整数点数/2-1 // POJ 2954 #include <iostream> #include <cstdio> #include ...
- effective c++:private继承
如果class间使用private继承关系,编译器就不会自动的将派生类转换为基类,而且private继承而来的成员都变为private属性. private继承意味着根据某物实现出,当我们想要避免重复 ...
- 【开源项目之路】jquery的build问题
在刚开始clone了jquery到本地build的时候,就遇到了问题. “ENORESTARGET No tag found that was able to satisfy ...” 提示为bowe ...
- Hadoop学习记录(6)|Eclipse安装Hadoop 插件
下载 https://skydrive.live.com/redir.aspx?cid=cf7746837803bc50&resid=CF7746837803BC50!1277&par ...
- 桶排序-C-结构体排序
struct TS { int index; ]; }; ] = {{,,,,,"s8"}}; ]; int i; int length = sizeof(a) / sizeof ...
- jq 写法
<!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...