• Codeforces442A


    A. Borya and Hanabi

    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

    Note

    In 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.

    题意

    有一个人知道有哪些牌,但是不知道这些牌是哪张。

    他每次可以问2个问题,

    1.x颜色的牌是哪些

    2.数值为y的牌是哪些

    然后问最少多少次询问,这个人才能分清哪些牌是哪些

    思路:

    我们把这些牌抽象成二维空间的点,然后我们开始画线

    如果这个平面上的点少于等于1个,那么我们就可以说明这个人已经分清了

    那么哪些点我们可以删去呢?只要这个点被两条线段覆盖,或者这条线段上只有这么一个点,那么这个点就是可以被删除的

    观察到一共有五种颜色,有五种数字,那么其实我们最多猜10次就一定能够得到结果了。

    那么考虑2^10枚举所有操作情况,那么对应暴力处理,判断结果是否可行,维护最小即可。

     1 //2018-08-12
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 const int N = 150;
    10 
    11 int x[N], y[N], info[N], n;
    12 
    13 int color_to_id(char ch){
    14     if(ch == 'R')return 1;
    15     if(ch == 'G')return 2;
    16     if(ch == 'B')return 3;
    17     if(ch == 'Y')return 4;
    18     if(ch == 'W')return 5;
    19 }
    20 
    21 int count_one(int x){
    22     int cnt = 0;
    23     while(x){
    24         cnt += (x&1);
    25         x >>= 1;
    26     }
    27     return cnt;
    28 }
    29 
    30 bool check(int sta){
    31     for(int i = 0; i < n; i++){
    32         info[i] = 0;
    33         info[i] |= (1<<(x[i]-1))&sta;
    34         info[i] |= (1<<(y[i]-1+5))&sta;
    35         for(int j = 0; j < i; j++)
    36             if(info[i] == info[j] && (x[i]!=x[j] || y[i]!=y[j]))
    37                   return false;
    38     }
    39     return true;
    40 }
    41 
    42 int main()
    43 {
    44     string str;
    45     while(cin>>n){
    46         for(int i = 0; i < n; i++){
    47             cin>>str;
    48             x[i] = color_to_id(str[0]);
    49             y[i] = str[1]-'0';
    50         }
    51         int ans = 10;
    52         for(int i = 0; i < (1<<10); i++){
    53             int n_one = count_one(i);
    54             if(n_one >= ans)continue;
    55             if(check(i))ans = n_one;
    56         }
    57         cout<<ans<<endl;
    58     }
    59 
    60     return 0;
    61 }
  • 相关阅读:
    5.11号团队冲刺(十)
    5.10号团队冲刺(九)
    python day04
    python day03
    python day02
    python day01
    模板语法标签继承关系
    DNS解析详情
    和域名相关的知识
    Webpack 4.X webpack.config.js 文件配置(一)
  • 原文地址:https://www.cnblogs.com/Penn000/p/9464932.html
Copyright © 2020-2023  润新知