博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 422A A. Borya and Hanabi(暴力)
阅读量:4883 次
发布时间:2019-06-11

本文共 3989 字,大约阅读时间需要 13 分钟。

题目链接:

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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.

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 题意: 现在知道有哪些牌,但不知具体顺序,每次询问都会知道这个询问的相关的牌的位置,问最少需要多少次询问; 思路: 变成二维的点,划线后被两次覆盖的点可以删去,剩下的一行或者一列只有一个的也可以删去了; 看最后如果剩下的个数<=1就这种选择就可行; AC代码:
#include 
using namespace std;typedef long long LL;const int maxn=5e5+10;int n,a[6][6],x[6],y[6],b[6][6],numx[6],numy[6];char s[2];int check(int temp){ for(int i=0;i<5;i++) for(int j=0;j<5;j++) b[i][j]=a[i][j]; for(int i=0;i<5;i++)if((temp>>i)&1)x[i]=1;else x[i]=0; for(int i=5;i<10;i++)if((temp>>i)&1)y[i-5]=1;else y[i-5]=0; for(int i=0;i<5;i++) { if(x[i]) { int num=0; for(int j=0;j<5;j++)if(b[i][j])num++; if(num==1) { for(int j=0;j<5;j++)b[i][j]=0; } } } for(int i=0;i<5;i++) { if(y[i]) { for(int j=0;j<5;j++) { if(b[j][i]&&x[j])b[j][i]=0; } int num=0; for(int j=0;j<5;j++)if(b[j][i])num++; if(num==1) { for(int j=0;j<5;j++)b[j][i]=0; } } } for(int i=0;i<5;i++) { if(x[i]) { int num=0; for(int j=0;j<5;j++)if(b[i][j])num++; if(num==1) { for(int j=0;j<5;j++)b[i][j]=0; } } } int num=0; for(int i=0;i<5;i++) for(int j=0;j<5;j++) if(b[i][j])num++; if(num>1)return 10; int ans=0;//cout<
<<"*****"<
>=1;} return ans;}int main(){ scanf("%d",&n); int fx,fy; for(int i=1;i<=n;i++) { scanf("%s",s); if(s[0]=='R')fx=0; else if(s[0]=='B')fx=1; else if(s[0]=='Y')fx=2; else if(s[0]=='W')fx=3; else fx=4; fy=s[1]-'0'-1; a[fx][fy]++; } int num=0; for(int i=0;i<5;i++) for(int j=0;j<5;j++) if(a[i][j])num++; if(num<=1){printf("0\n");return 0;} int ans=10; for(int i=0;i<(1<<10);i++)ans=min(ans,check(i)); cout<
<

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5942713.html

你可能感兴趣的文章
Excel导数据到数据库
查看>>
zz 悲催的程序员,以及程序员的悲催
查看>>
Thinkphp 3.2笔记
查看>>
RHEL7开机不能正常进入系统(图形化界面)
查看>>
Android开发环境搭建完全图解
查看>>
详解BOM头以及去掉BOM头的方法
查看>>
PHP 手机浏览器访问网站获取手机相关信息方法集锦
查看>>
09年电子竞赛参赛技巧经验11条(转载)
查看>>
CSS颜色
查看>>
前端自动化之(一)—浏览器自动实时刷新
查看>>
Unity 摄像头竖屏预览显示的问题
查看>>
HDU 5115 Dire Wolf(区间dp)
查看>>
C# 程序配置文件的操作(ConfigurationManager的使用)
查看>>
Springmvc完成分页的功能
查看>>
JComboBox实现当前所选项功能和JFrame窗口释放资源的dispose()方法
查看>>
tp 引入phpexcel 进行单表格的导入,在线浏览
查看>>
jsp基础速成精华讲解
查看>>
URL to Blob
查看>>
bzoj 3643: Phi的反函数
查看>>
BizTalk Server 2009 Beta初体验
查看>>